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.

Shuffle array int string Java Android


AD MOB


String [] arOfStrings = {"one", "two", "three"};
List<String> mListOfStrings = new ArrayList<String>(Arrays.asList(arOfStrings));
Collections.shuffle(mListOfstrings);
String str = mListOfStrings.get(2);// 2 is index of pozition an element


int [] arOfInt = {1, 2, 3};
List<Integer> mListOfInt = new ArrayList<Integer>(Arrays.asList(arOfInt));
Collections.shuffle(mListOfInt);

397LW NO topic_id




AD

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


328

Screen size density independent pixel resolution | screen-size-density-independent-pixel-resolution


Terms Screen size, density, density independent pixel, resolution as a picture - pictogram.
mobile-phone-screen-resolution-terms

Test your knowledge
Q: How to find out the phone screen size?
A: (By length of display diagonale in inch -  Not to measure a diagonal of device!!!)

Q: What resolution has 720 x 1280 display?
A: (921600 pixels)

Q: What does it mean "240 dpi" screen density?
A: (Display have density 240 x 240  dots - "Tri-color LED etc." - per every physical (real) square inch. If you have icon 240x240 pixels, this will just occupy an area of one square inch on the display.)

Q: Phone have screen density 240 dpi. Image for 160 dpi screen density have size 128x 128 pixels. What will be the size of the image for 240 dpi screen density?
A: (Calculate the virtual pixels size.   128 * (240/160)  =  192.  You have to resize image to new size 192 x 192 physical pixels and put into folder drawable-hdpi (high) ~240dpi  for phone with screen density 240 dpi. ) or use density independend pixels 128dp x 128dp.

 

 
231

Date getDate is deprecated Java Android | date-getdate-is-deprecated-java-android


Date getDate is deprecated Java Android example code:


long dayInMili = 100000000;

GregorianCalendar calToDay = new GregorianCalendar();
int nD = calToDay.get((Calendar.MILLISECOND)); // +dayInMili;
System.out.println(nD);

long lTime = calToDay.getTimeInMillis();
System.out.println(lTime);

Date dtA = new Date(lTime); // today
///@SuppressWarnings("deprecation")
int nD1 = dtA.getDate(); // DEPRECATED Day Of Month 1 - 31
System.out.println(nD1+" nD1");

GregorianCalendar cal = new GregorianCalendar();
int nD2 = calToDay.get(Calendar.DATE); // Day Of Month
System.out.println(nD2+" nD2");

cal.setTimeInMillis(lTime+dayInMili);// setTime(dtA);
int nD3 = cal.get(Calendar.DATE); // Day Of Month + 1 day
System.out.println(nD3+" nD3");


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
17

double in Java example for Android development | double-in-java-example-for-android-development


Java double is 64 bit double precision type used when fractional
precision calculation is required.

Java double je datový typ (reálné číslo) o velikosti 64 bitů. Používá se například pro přesný výsledek po dělení za desetinnou tečkou. Pokud nepotřebuje tak veliké číslo použijte raději typ float, šetříte tím paměť mobilního telefonu.


		// declaration and assignment of value  type double
		double x = 18.41785;
		//print formated  value
		System.out.printf("The value of x is %.3f%n", x); // 18.418
                
                // declaring more variables in single statement
                double d1 = 12.4, d2 = 564.5, d3 = 14.589;

		// double range of value
		System.out.println(Double.MIN_VALUE); // 4.9E-324
		System.out.println(Double.MAX_VALUE); // 1.7976931348623157E308

		// is NaN  Not-a-Number
		double f = (double) Math.sqrt(-15);
		boolean bNaN = Double.isNaN(f);
		System.out.print(bNaN); // true
		
                // check if a string is a valid number in Java example
                // convert string to double Java example
		String sD = "12.8";
		double dParse = Double.parseDouble(sD);

	       // convert strings to numbers
	      String sDl = "15.48";
	      double dFromString = (Double.valueOf(sDl)).doubleValue();

// format double, float or long value to string
	DecimalFormat formatter = new DecimalFormat(".##");
	String s = formatter.format(-.5678);             // -0.57
// .###  -0.568
// .#### -0.5678
// .000000  -.567800

// -123.456
// .##  -123.46
// #.##  -123.46

// #E0  -.1E3
// ##E0  -1.2E2
//###E0  -123E0

// double to string in Java example code
Double dObj = new Double(68.5);
String str = dObj.toString();
// else 
Double dS = 11.6;
String sdouble = dS.toString();

// compare two double variables
	      Double dComp1 = 4.3;
	      if(dComp1.equals(4.3))
	  		System.out.print("true");

	// compares the two specified double values in Java example
	// int i =	compare(double d1, double d2);
	    int i =	Double.compare(11.5, 11.7); // -1 first < second
	    // 0 first == second
	    // 1 first > second
	    System.out.print(i);


4

Read file from URL | read-file-from-url


Read file from URL to array of byte and convert to UTF-8 String Android examle source code.

URL urlLoc = new URL("//myweb.com/myfile.html");
URLConnection conexion = urlLoc.openConnection();
conexion.setConnectTimeout(4000);
conexion.setReadTimeout(1000);
conexion.connect();

// downlod the file
InputStream input = new BufferedInputStream(urlLoc
		.openStream());

StringBuffer responseBuffer = new StringBuffer();
byte[] byteArray = new byte[1024];
while (input.read(byteArray) != -1)
 {   
        String res = new String(byteArray, "UTF-8");
        responseBuffer.append(res);
        byteArray = null;
        byteArray = new byte[1024];
 }

String response = responseBuffer.toString().trim();





Editace: 2013-12-09 11:05:54
Počet článků v kategorii: 397
Url:shuffle-array-int-string-java-android

AD
11 Share
Share
Tweet