Help me do a small modification of android - Nexus 5 Q&A, Help & Troubleshooting

I have found the file to modify
/overlay/frameworks/base/core/res/res/values/config.xml
Code:
- <!-- Shutdown if the battery temperature exceeds (this value * 0.1) Celsius. -->
- <integer name="config_shutdownBatteryTemperature">600</integer>
BatteryService.java reads this value and compares with the temperature reading and issues a shutdown command.
Code:
private void shutdownIfOverTempLocked() {
// shut down gracefully if temperature is too high (> 68.0C by default)
// wait until the system has booted before attempting to display the
// shutdown dialog.
if (mBatteryProps.batteryTemperature > mShutdownBatteryTemperature) {
mHandler.post(new Runnable() {
@Override
public void run() {
if (ActivityManagerNative.isSystemReady()) {
Intent intent = new Intent(Intent.ACTION_REQUEST_SHUTDOWN);
intent.putExtra(Intent.EXTRA_KEY_CONFIRM, false);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivityAsUser(intent, UserHandle.CURRENT);
}
}
});
How do I modify this value?

Related

home screen widget ui problem

Hello,
i created a widget that uses a service with wakelock to update and parse data from an xml and update the widget's ui so that items would rotate every few seconds (standard news feed widget).
the problem is that the ui stops updating after a few hours although the data keeps updating.
here's the code i am using to update the ui
Code:
mUpdateTimeTask = null;
mUpdateTimeTask = new Runnable()
{
public void run()
{
if(which_item+1 < Widget_titles.length)
which_item++;
else
which_item = 0;
if(Widget_which_item_ed != null)
{
Widget_which_item_ed.putInt("WIDGET_WHICH_ITEM", which_item);
Widget_which_item_ed.commit();
}
else
{
Widget_which_item = context.getSharedPreferences("WIDGET_WHICH_ITEM", Context.MODE_WORLD_WRITEABLE);
Widget_which_item_ed = Widget_which_item.edit();
Widget_which_item_ed.putInt("WIDGET_WHICH_ITEM", which_item);
Widget_which_item_ed.commit();
}
updateViews.setTextViewText(R.id.WidgetText, Widget_titles[which_item]);
updateViews.setTextViewText(R.id.WidgetPostTime, rightNow.get(Calendar.MONTH)+"/"+rightNow.get(Calendar.DATE)+"/"+rightNow.get(Calendar.YEAR));
manager = AppWidgetManager.getInstance(context);
manager.updateAppWidget(WidgetId, updateViews);
mHandler.removeCallbacks(mUpdateTimeTask);
mHandler.postDelayed(this, widget_interval * 1000);
}
};
mHandler.postDelayed(mUpdateTimeTask, widget_interval * 1000);
Log.i(TAG, "sliding update handler was configed");
i am really stuck and could really use help
Edit:
i managed to go around this problem by implementing the BroadCastReciever for the screen on/off intents as shown in a tutorial i found (i can't post it here - the forum won't let me-sorry)
and therefore the amount of time that the widget needs to run is much smaller.

Why my items are not redrawn after invoking `invalidateViews()` ?

Why my items are not redrawn after invoking `invalidateViews()` ?
I ask because i try to refresh `listItems` after a bg-thread notify an image rsc was downloaded.
But nothing is updated. Only after exiting and re-entering the new icons are drawn.
I have an activity with `adapter` of type `SettingValueAdapter extends BaseAdapter`
it has a member:
`private SettingsValue[] values;`
it has two interesting methods:
@override
public View getView(int position, View view, ViewGroup parent) {
AddressItem ai= (AddressItem)getItem(position);
DriveToNativeManager dnm = DriveToNativeManager.getInstance();
if (view == null) {
LayoutInflater li = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = li.inflate(R.layout.address_item, null);
}
view.setTag(R.id.addressItem,ai);
view.setTag(position);
view.findViewById(R.id.fullAddressItemCol).setVisibility(View.VISIBLE);
view.findViewById(R.id.addressItemTouch).setVisibility(View.GONE);
view.findViewById(R.id.addressItemImage).setVisibility(View.GONE);
if (ai != null) {
...
}
view.findViewById(R.id.addressItemIconLayout).setVisibility(View.VISIBLE);
Drawable icon = ResManager.GetSkinDrawable(ai.getIcon() + ".bin");
((ImageView)view.findViewById(R.id.addressItemIcon)).setImageDrawable(icon);
..
}
I attach a callback to the bg-thread (c language) image downloading process.
The callback switches to the ui-thread and calls this `refreshList`:
public void refreshSearchIconsOnSearchActivity() {
Runnable refreshViewEvent = new Runnable() {
@override
public void run() {
Activity currentActivity = AppService.getActiveActivity();
if (currentActivity instanceof SearchActivity) {
Log.d("w", "refreshSearchIconsOnSearchActivity callback running in thread "
+ Thread.currentThread().getId() );
//results list
((SearchActivity) currentActivity).refreshList();
}
}
};
AppService.Post(refreshViewEvent);
}
However, the images are done downloading and are not refreshed on the activity.
They are refreshed only when I leave an re-enter the activity.
What am I missing?

Google Play Game Services in libgdx

The article was written in the course of the game's development CLEAR SKY 2
The first part here!
Code
In the main Activity implement two interfaces GameHelperListener, ActionResolver:
public class MainActivity extends AndroidApplication implements GameHelperListener, ActionResolver
GameHelperListener interface is as follows:
Code:
public interface GameHelperListener {
/ **
* Called when an attempt to login. This method can show
* User button «Sign-in» for manual entry
* /
void onSignInFailed ();
/ ** Called when a successful login attempt * /
void onSignInSucceeded ();
}
Interface ActionResolver create ourselves. He needed to call the platform-dependent code. This technique is described in the official wiki libgdx. An example of the interface:
Code:
public interface ActionResolver {
/ ** Check the status of the user input * /
public boolean getSignedInGPGS ();
/ ** Log * /
public void loginGPGS ();
/ ** Send the result in the high score table * /
public void submitScoreGPGS (int score);
/ **
* Unlock achievement
*
*param AchievementId
* ID achievements. Taken from the file games-ids.xml
* /
public void unlockAchievementGPGS (String achievementId);
/ ** Show Activity records to the table * /
public void getLeaderboardGPGS ();
/ ** Show Activity achievements * /
public void getAchievementsGPGS ();
}
Example code main Activity:
Code:
public class MainActivity extends AndroidApplication implements
GameHelperListener, ActionResolver {
// Assistant to work with gaming services
private GameHelper gameHelper;
// Class of our games
private TestGame game;
Override
public void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
// CLIENT_ALL instruct you on the use of the API all customers
gameHelper = new GameHelper (this, GameHelper.CLIENT_ALL);
// Disable automatic login when starting the game
gameHelper.setConnectOnStart (false);
gameHelper.enableDebugLog (true);
// From turning off the screen without the use of additional
// Permits (less than permissions - more confidence in the application)
getWindow (). addFlags (WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
// Input parameter this is ActionResolver. Allows you to call from
// Game loop platform-specific methods GPGS
game = new TestGame (this);
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration ();
initialize (game, config);
gameHelper.setup (this);
}
// Methods gameHelper'a: onStart (), onStop () are called to work correctly
// GPGS in the lifecycle of android-app
Override
protected void onStart () {
super.onStart ();
gameHelper.onStart (this);
}
Override
protected void onStop () {
super.onStop ();
gameHelper.onStop ();
}
Override
protected void onDestroy () {
super.onDestroy ();
}
Override
protected void onActivityResult (int requestCode, int resultCode, Intent data) {
super.onActivityResult (requestCode, resultCode, data);
// Here gameHelper decides to connect, or reconnect
// Disconnected from the game services, depending on the result code
// Activity
gameHelper.onActivityResult (requestCode, resultCode, data);
}
Override
public boolean getSignedInGPGS () {
// Connection status
return gameHelper.isSignedIn ();
}
Override
public void loginGPGS () {
try {
runOnUiThread (new Runnable () {
Override
public void run () {
// Initiate user entry. Can be called a dialogue
// Login. Performed in UI-stream
gameHelper.beginUserInitiatedSignIn ();
}
});
} Catch (Exception e) {
e.printStackTrace ();
}
}
Override
public void submitScoreGPGS (int score) {
// Send game points to a specific table records with ID
// "HgkIr62KmoQJEAIQAQ"
Games.Leaderboards.submitScore (gameHelper.getApiClient (),
"HgkIr62KmoQJEAIQAQ", score);
}
Override
public void unlockAchievementGPGS (String achievementId) {
// Open achievement with ID achievementId
Games.Achievements.unlock (gameHelper.getApiClient (), achievementId);
}
Override
public void getLeaderboardGPGS () {
Activity // call for all registered tables records. as
Activity // can call for a specific table
startActivityForResult (
Games.Leaderboards.getAllLeaderboardsIntent (gameHelper
.getApiClient ()), 100);
}
Override
public void getAchievementsGPGS () {
// Call Activity achievements
startActivityForResult (
Games.Achievements.getAchievementsIntent (gameHelper
.getApiClient ()), 101);
}
Override
public void onSignInSucceeded () {
}
Override
public void onSignInFailed () {
}
}
Suppose we have in the game provided the achievement - to collect 1 million. Player points, the code implementing it would look like this:
Code:
public static void checkTotalPoints (int points) {
ActionResolver res = getActionResolver ();
if (! res.getSignedInGPGS ()) {
return;
}
if (points> = 1000000) {
res.unlockAchievementGPGS ("HgkIr62KmoQJEAIQGA");
}
}
Same thing with a table of records, only even easier: you just need to call the submitScoreGPGS (int score) interface ActionResolver.
PS To test gaming services need to export apk-file with the same certificate as in the developer console. Just need to add accounts testers in the console. Changes in gaming services come into effect after a while.
Google Play Clear Sky 2
Long second part released!
sources used
developers.google.com/games/services/android/quickstart
developer.android.com/intl/ru/google/play-services/setup.html
github.com/libgdx/libgdx/wiki
Please don't add the &hl=ru parameter to your Play Store links - then it is in Russian for all users. Without it, native language is used.

SeekBar value isn't actualized in while loop

I am trying to create a flashlight app with a strobe (blink) effect which I can change with a SeekBar (to change the frequency of the strobe).My goal is that I would be able to change the frequency while it's ON (blinking) and if the Seekbar value goes to 0 the Flash should be ON(without strobe/blinking). My problem is that I can turn it ON (with a Switch Btn, but if I increase the frequency once I am not able to turn OFF the strobe (but the Flash is still ON without blinking) with the Seekbar. If I put the Seekbar value to 0 it's still blinking with the lowest frequency.
I would be so glad if you could help me.
Camera cam;
Parameters camParams;
boolean hasCam;
int freq;
StroboRunner sr;
Thread t;
SeekBar seekBar;
Switch mySwitch;
SeekBar skBar;
 @override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mySwitch = (Switch) findViewById(R.id.mySwitch);
// set the Switch to off
mySwitch.setChecked(false);
//now you need a listener to check changes in state
mySwitch.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
turnOnOff(isChecked);
}
});
skBar = (SeekBar) findViewById(R.id.seekBar);
skBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
freq = progress;
}
@override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
}
 @override
protected void onResume() {
super.onResume();
try {
cam = Camera.open();
camParams = cam.getParameters();
cam.startPreview();
hasCam = true;
}catch(Exception e){
}
}
private void turnOnOff(boolean on){
if(on) {
if(freq != 0){
sr = new StroboRunner();
t = new Thread(sr);
t.start();
return;
}else{
camParams.setFlashMode(Parameters.FLASH_MODE_TORCH);
}
}else if(!on){
if(t != null){
sr.stopRunning = true;
t =null;
return;
}else{
camParams.setFlashMode(Parameters.FLASH_MODE_OFF);
}
}
cam.setParameters(camParams);
cam.startPreview();
}
private class StroboRunner implements Runnable {
boolean stopRunning = false;
@override
public void run() {
Camera.Parameters paramsOn = cam.getParameters();
Camera.Parameters paramsOff = camParams;
paramsOn.setFlashMode(Parameters.FLASH_MODE_TORCH);
paramsOff.setFlashMode(Parameters.FLASH_MODE_OFF);
try {
while (!stopRunning) {
cam.setParameters(paramsOn);
cam.startPreview();
Thread.sleep((100 - freq)*1);
cam.setParameters(paramsOff);
cam.startPreview();
Thread.sleep((100 - freq)*1);
}
}catch(Exception e){
}
}
}
}

CountDownTimer inside Android app stops when using Google Search widget?

I'm showing the timer in the TextView. I'm adding the code for onPause and onResume method.
Below is the code for countDownTimer. I call this method from the onResume method.
Code:
public void startCountDownTimer() {
countDownTimer = new CountDownTimer(total, 1000) {
public void onTick(long millisUntilFinished) {
total = millisUntilFinished;
completedMin = (int) (TimeUnit.MILLISECONDS.toMinutes(millisUntilFinished) - TimeUnit.HOURS.toMinutes(
TimeUnit.MILLISECONDS.toHours(millisUntilFinished)));
sessionTimerTextView.setText("" + String.format(TIME_FORMAT,
TimeUnit.MILLISECONDS.toHours(millisUntilFinished),
TimeUnit.MILLISECONDS.toMinutes(millisUntilFinished) - TimeUnit.HOURS.toMinutes(
TimeUnit.MILLISECONDS.toHours(millisUntilFinished)),
TimeUnit.MILLISECONDS.toSeconds(millisUntilFinished) - TimeUnit.MINUTES.toSeconds(
TimeUnit.MILLISECONDS.toMinutes(millisUntilFinished))));
}
public void onFinish() {
sessionTimerTextView.setText("00:00:00");
}
};
countDownTimer.start();
}
Below is the code for onResume method
Code:
@Override
protected void onResume() {
Log.d(TAG, "onResume");
super.onResume();
startCountDownTimer();
}
Below is the code for onPause method
Code:
@Override
protected void onPause() {
super.onPause();
}
The code works fine when I minimize the app and open any other app but when I use the Google search widget then the timer inside my app stops. What should I do to resolve the issue?

Categories

Resources