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.

List LinkedList add sort find Item in Java example


AD MOB

List LinkedList Collections add sort find search Item, get searched item to string in Java example.

MainClass.java

import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

public class MainClass {
	public static void main(String[] arg) {
		String[] arrayOfString = {"nothing", "Hello", "people"
				, "bye-bye", "hello", "world!", "End" };
		   
                   List<String> arrayList = new LinkedList<String>();
                  
                   for(String s: arrayOfString)
		     arrayList.add(s);

		    Collections.sort(arrayList);
		    // foreach
		    for (String str: arrayList)
		      System.out.println(str);
		    
		    Object objMin = Collections.min(arrayList);
		    System.out.println("Min is: " + objMin);
		    
		    Object objMax = Collections.max(arrayList);
		    System.out.println("Max is: " + objMax);
		    
		    int index = Collections.binarySearch(arrayList, "people");
		    System.out.println("Index of people is: " + index);
		    // print word on index 5
		    System.out.println("Index 5 is: " + arrayList.get(5));
                    String sItem = arrayList.get(5); // get item from index 5 to string
		    
		  }
}
/*
End
Hello
bye-bye
hello
nothing
people
world!
Min is: End
Max is: world!
Index of people is: 5
Index 5 is: people
*/

397LW NO topic_id




AD

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


151

Bitmap Canvas Color Gradient linear radial sweep rounded corner Android example | bitmap-canvas-color-gradient-linear-radial-sweep-rounded-corner-android-example



public class MainActivity extends Activity {
//  //www.apache.org/licenses/LICENSE-2.0
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(new SampleView(this));
	}

	   private static class SampleView extends View {
	        private Rect    mRect;
	        private GradientDrawable mDrawable;

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

	            mRect = new Rect(0, 0, 220, 120);
	      
/*	            GradientDrawable.Orientation  BL_TR  draw the gradient from the bottom-left to the top-right   
	              BOTTOM_TOP  draw the gradient from the bottom to the top   
	              BR_TL  draw the gradient from the bottom-right to the top-left   
	              LEFT_RIGHT  draw the gradient from the left to the right   
	              RIGHT_LEFT  draw the gradient from the right to the left   
	              TL_BR  draw the gradient from the top-left to the bottom-right   
	              TOP_BOTTOM  draw the gradient from the top to the bottom   
	              TR_BL  draw the gradient from the top-right to the bottom-left   
*/
	            
	            mDrawable = new GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT,
	                                             new int[] { 0xFFFF0000, 0xFF00FF00,
	                                                 0xFF0000FF });
	            mDrawable.setShape(GradientDrawable.RECTANGLE);
	            mDrawable.setGradientRadius((float)(Math.sqrt(2) * 60));
	        }
	        
	        static void setCornerRadius(GradientDrawable drawable, float r0,
	                                   float r1, float r2, float r3) {
/*	        	setCornerRadii
	        	Specify radii for each of the 4 corners. For each corner, 
	        	the array contains 2 values, [X_radius, Y_radius]. 
	        	The corners are ordered top-left, top-right, bottom-right, 
	        	bottom-left 
*/
	            drawable.setCornerRadii(new float[] { r0, r0, r1, r1,
	                                                  r2, r2, r3, r3 });
	        }
	        
	        @Override protected void onDraw(Canvas canvas) {
	            
	            mDrawable.setBounds(mRect);

	            float r = 35;
	            
	            canvas.save();
	            canvas.translate(10, 10);
	            mDrawable.setGradientType(GradientDrawable.LINEAR_GRADIENT);
	            setCornerRadius(mDrawable, r, r, 0, 0);
	            mDrawable.draw(canvas);
	            canvas.restore();
	            
	            canvas.translate(0, mRect.height() + 10);
	            canvas.save();
	            canvas.translate(10, 10);
	            mDrawable.setGradientType(GradientDrawable.RADIAL_GRADIENT);
	            setCornerRadius(mDrawable, 0, 0, r, r);
	            mDrawable.draw(canvas);
	            canvas.restore();
	            
	            canvas.translate(0, mRect.height() + 10);
	            canvas.save();
	            canvas.translate(10, 10);
	            mDrawable.setGradientType(GradientDrawable.SWEEP_GRADIENT);
	            setCornerRadius(mDrawable, 0, r, r, 0);
	            mDrawable.draw(canvas);
	            canvas.restore();
	            
	            
	        }
	    }
	}


gradient-bitmap-rounded
187

NoClassDefFoundError: com.google.ads.AdView ADT 17 | noclassdeffounderror-com-google-ads-adview-adt-17


Eclipse update ADT 17 Android Emulator error: E/AndroidRuntime(370): java.lang.NoClassDefFoundError: com.google.ads.AdView

Solution:
-right click on the project in project tree and select Project properties
-select Java Build Path
-select TAB Order and Export
-check GoogleAdMobAdsSdk-4.0.4.jar (or your version SDK)
-press OK
-clean project by menu Project -> Clean
-rebuild project (Project - Build Automatically)

How add GoogleAdMobAdsSdk....jar to project:
-right click on the project in project tree and select Project properties
-select Java Build Path
-select TAB Libraries
-press the button Add External JARs...
-select your version GoogleAdMobAdsSdkXXX.jar what you can using
-OK
-OK
-clean project
-rebuild project


menu-item-project-properties-eclipse
order-and-export-eclipse dialogue
eclipse-add-jar-library-to-project
144

Compressing a bitmap to JPG format Android example | compressing-a-bitmap-to-jpg-format-android-example


Codec, compress(), CompressFormat, quality, decodeByteArray(), Android example source code with image.

public class MainActivity extends Activity {
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(new SampleView(this));
	}

	private static Bitmap codec(Bitmap src, Bitmap.CompressFormat format,
			int quality) {
		ByteArrayOutputStream os = new ByteArrayOutputStream();
		src.compress(format, quality, os);

		byte[] array = os.toByteArray();
		return BitmapFactory.decodeByteArray(array, 0, array.length);
	}

	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.GRAY);
            
                        //  you need to insert some image flower_blue into res/drawable folder
			Bitmap b = BitmapFactory.decodeResource(getResources(), R.drawable.flower_blue);
                        // Best of quality is 80 and more, 3 is very low quality of image 
			Bitmap bJPGcompress = codec(b, Bitmap.CompressFormat.JPEG, 3);
                   // get dimension of bitmap getHeight()  getWidth()
		   int h = b.getHeight();
           
           canvas.drawBitmap(b, 10,10, paint);
           canvas.drawBitmap(bJPGcompress, 10,10 + h + 10, paint);
           
		}

	}
}



jpg compression android
284

WAV Sound Quality is Poor Android MediaPlayer | wav-sound-quality-is-poor-android-mediaplayer


Try convert WAV file to MP3 format for example by Audacity sound editor and replay:
//audacity.sourceforge.net/help/faq_i18n?s=install&i=lame-mp3


MediaPlayer mp  = MediaPlayer.create(getApplicationContext(), R.raw.mymp3file);
mp.setLooping(true);
mp.start();

77

break statement in Java Android example | break-statement-in-java-android-example


break statement in Java Android basic example

MainClass.java

public class MainClass {
	public static void main(String[] arg) {
		String[] arrayOfString = {"nothing", "Hello", "people"
				, "bye-bye", "hello", "world!", "end" };
		
		for (int i = 0; i < arrayOfString.length; i++) {
				System.out.println(arrayOfString[i]);
				if(i > 2) 
					break; // end of loop
		}
	}
}
/*
nothing
Hello
people
bye-bye
*/


Editace: 2013-12-09 10:56:55
Počet článků v kategorii: 397
Url:list-linkedlist-add-sort-find-item-in-java-example

AD
11 Share
Share
Tweet