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 SensorManager PowerManager WindowManager Display Android example


AD MOB


    private SensorManager mSensorManager;
    private PowerManager mPowerManager;
    private WindowManager mWindowManager;
    private Display mDisplay;

// onCreate
   @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

       // Get an instance of the SensorManager
        mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);

        // Get an instance of the PowerManager
        mPowerManager = (PowerManager) getSystemService(POWER_SERVICE);

        // Get an instance of the WindowManager
        mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
        mDisplay = mWindowManager.getDefaultDisplay();

        setContentView(R.layout.main); // main.xml or your xml file name

}


397LW NO topic_id




AD

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


251

How to create icon for Android apps | how-to-create-icon-for-android-apps


First cteate big icon 512x512 px formtat .PGN in graphics editor as Photoshop, Gimp, Piant.NET and save image.
If you create new project via Eclipse and choice your 512x512 image for ic_launcher.
Eclipse will make all icons from this image for new application very well.

create-custom-icon-eclipse

create-custom-icon-eclipse
288

Eclipse - Java was started but returned exit code=13 | eclipse-java-was-started-but-returned-exit-code13


Windows 7 64-bit version.
Eclipse 64-bit - Java was started but returned exit code=13

Solution:
Download and install 64-bit version of JDK
//www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html
367

View getId is null Android | view-getid-is-null-android


If you create a button or view programmatically with OnClickListener you can set a tag key before button in parent layout is added.
And get correct button by this tag getTag() instead getId() in OnClickListener etc.

Button button = new Button(getApplicationContext());
int idOfButton = button.getId(); // return -1

button.setTag("my_button");
String sTag = (String) button.getTag(); // return "my_button"

173

Custom View Android Basic Example | custom-view-android-basic-example


Activity.java

public class A extends Activity{
	Bitmap bm;
	 TouchImageView touch;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		 setContentView(R.layout.main);
		 
		 bm = BitmapFactory.decodeResource(getResources(), R.drawable.chinese_sky_map);
 		 touch =  (TouchImageView)findViewById(R.id.myImageView);
	  touch.setImageBitmap(bm);
		 
	}
}


\res\layout\main.xml


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="//schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >


    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello" />

    <cz.okhelp.TouchImageView.TouchImageView
        android:id="@+id/myImageView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        
        />

</LinearLayout>



location TouchImageView\src\cz\okhelp\TouchImageView\TouchImageView.java

public class TouchImageView extends ImageView {


    Context context;

// constructor wihtout using  *.xml file
//    public TouchImageView(Context context) {
//        super(context);
// }

// constructor with xml file
    public TouchImageView(Context context, AttributeSet attrs)
    {
      super(context, attrs);
      super.setClickable(true);
        this.context = context;
  }
}

226

R.string to string R.array to array Android | r-string-to-string-r-array-to-array-android


R.string to string Android source code
R.array to string [] Android source code

String s = getResources().getString(R.string.my_string); // Hello world!!
String[] arrayOfStrings = getResources().getStringArray(R.array.my_array); // one, two


<xml version="1.0" encoding="utf-8">
<resources>
    <string-array name="my_array">
        <item>one</item>
        <item>two</item>
    </string-array>
<string name="my_string">Hello world!!</string>
</resources>


Editace: 2011-11-07 11:43:11
Počet článků v kategorii: 397
Url:get-sensormanager-powermanager-windowmanager-display-android-example

AD
11 Share
Share
Tweet