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 the color of a specific pixel Java Android example


AD MOB


             ImputStream      is = this.getResources().openRawResource(R.drawable.colors);
             Bitmap    mBitmap2 = BitmapFactory.decodeStream(is);
        
         int  w = mBitmap2.getWidth();
         int  h = mBitmap2.getHeight();
//  int x , y have to be smaller as w , h 
         int _color =  mBitmap2.getPixel(x, y);


397LW NO topic_id




AD

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


1

Create TextView dynamically Android sample | create-textview-dinamically


Example source code for Android Developers

// clickable TextView
public TextView createTextView(String sText, Context con){
 TextView b = null;
 try {
  b = new TextView (con);
  b.setTextSize(15.0f);
  b.setTextColor(Color.rgb( 0, 0, 200));
  b.setOnClickListener(this);
  b.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
  LayoutParams.WRAP_CONTENT));
  b.setText(sText);
  //tr.addView(b, 60,30);
  } catch (Exception e) {
  e.printStackTrace();
 return b;
 }
return b;
}
/*****************/
public void onClick(View view) {
 try {
  String s = ((TextView) view).getText().toString();
 }
 catch (Exception e1) {
   e1.printStackTrace();
 }
}
/***********/

// if you want restore in TextView after chagne of orientation
// you have to put  code to Manifest.xml android:configChanges

activity android:name=".main"
android:label="@string/app_name"
android:configChanges="keyboardHidden|orientation" //this line important !!!!!!!

40

Spinner ComboBox DropDown set on selected item listener setOnItemSelectedListener Java Android example | spinner-combobox-set-on-selected-item-listener-setonitemselectedlistener-java-android-example


Spinner, ArrayAdapter, setOnItemSelectedListener, onItemSelected, setDropDownViewResource

MainClass.java

public class Vypocet extends Activity {
 Spinner   hSpinnerMetry;
// .......
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

	       hSpinnerMetry = (Spinner) findViewById(R.id.idSpinnerMetry);
	        ArrayAdapter<CharSequence> adapterMetry = ArrayAdapter.createFromResource(
	        		this, R.array.metry_array, android.R.layout.simple_spinner_item);
	        adapterMetry.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
	        hSpinnerMetry.setAdapter(adapterMetry);
			
	           hSpinnerMetry.setOnItemSelectedListener(
	                    new OnItemSelectedListener() {
	                        public void onItemSelected(
	                                AdapterView<?> parent, View view, int position, long id) {
	                        int nPos = position;
	                        }

	                        public void onNothingSelected(AdapterView<?> parent) {
	                        
	                        }
	                    });	        

      }
}



strings.xml


<string-array name="metry_array">
<item>m</item>
<item>dm</item>
<item>cm</item>
<item>mm</item>
</string-array>


127

Force Screen On - dont use WakeLock - use getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) - Android sample | force-screen-on-dont-use-wakelock-use-getwindow-addflagswindowmanager-layoutparams-flag_keep_screen_on-android-sample


FLAG_KEEP_SCREEN_ON saving energy. Protects the battery if a user closing applications using the Return button on device. The device will returned to user screen mode settings.

@Override
    protected void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        //..........
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    }
289

Call requires API level xx current min is xx android | call-requires-api-level-xx-current-min-is-xx-android


Call requires API level 16 (current min is 4): android
Change The SDK version in AndroidManifest.xml to higher


<uses-sdk android:minSdkVersion="4" />
// 
<uses-sdk android:minSdkVersion="8" />
67

File open read to StringBuilder close Java example | file-open-read-to-stringbuilder-close-java-example


BufferedReader , FileReader, StringBuilder , readLine, close Java example

Android example

String MYFILE = "my_file";
FileInputStream fis = openFileInput(MYFILE);
	int c; String sText = "";
	while((c=fis.read())!=-1)
	{

		sText += (char)c; // convert int to char
	 }
	fis.close();						



Java example

try {
	    BufferedReader in = new BufferedReader(new FileReader("myfile.txt"));
	    StringBuilder strBuilder = new StringBuilder();
	    String str;
	    while ((str = in.readLine()) != null) {
	       strBuilder.append(str);
	    }
	    in.close();
	} catch (IOException e) {
		e.toString();
	}



Editace: 2013-12-09 13:06:02
Počet článků v kategorii: 397
Url:get-the-color-of-a-specific-pixel-java-android-example

AD
11 Share
Share
Tweet