In case that when I was using the dictionary on mobile, the screen darkens and later locked unless we kept on touching it . It is really strange that why the dictionary providers forget about it, since we all know the mobie is very frequently used when we are studying English or doing sth else.
So, I wrote an android program here to solve the issue. The code is simple , here are some notes:
1. How to get the wakelock?
mPowerManager = (PowerManager) getSystemService(POWER_SERVICE); mWakeLock = mPowerManager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, getClass().getName());
2. How to set the backgroud color of the actvity?
ll = (LinearLayout)findViewById(R.id.root);
ll.setBackgroundColor(Color.BLACK);
3. How to change the background of the imagebutton?
Resources rs = getBaseContext().getResources(); if ("ON".equals(mState)) { Drawable da = rs.getDrawable(R.drawable.turnon); mImageButton.setBackground(da); } else { Drawable da = rs.getDrawable(R.drawable.turnoff); mImageButton.setBackground(da); }
4. How to place the picture in the center of the screen?
<LinearLayout ..... android:gravity="center_vertical" android:id="@+id/root" ..... /> <ImageButton ..... android:layout_gravity="center|center_vertical" .... />
Screenshots
2013-08-10