Example usage for android.content Intent ACTION_POWER_USAGE_SUMMARY

List of usage examples for android.content Intent ACTION_POWER_USAGE_SUMMARY

Introduction

In this page you can find the example usage for android.content Intent ACTION_POWER_USAGE_SUMMARY.

Prototype

String ACTION_POWER_USAGE_SUMMARY

To view the source code for android.content Intent ACTION_POWER_USAGE_SUMMARY.

Click Source Link

Document

Activity Action: Show power usage information to the user.

Usage

From source file:hmatalonga.greenhub.ui.MainActivity.java

@Override
public boolean onMenuItemClick(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.action_settings:
        startActivity(new Intent(this, SettingsActivity.class));
        return true;
    case R.id.action_summary:
        startActivity(new Intent(Intent.ACTION_POWER_USAGE_SUMMARY));
        return true;
    }/*  ww w.  j  a v a  2 s  .  c  o  m*/

    return false;
}

From source file:com.hmatalonga.greenhub.ui.MainActivity.java

@Override
public boolean onMenuItemClick(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.action_inbox:
        startActivity(new Intent(this, InboxActivity.class));
        return true;
    case R.id.action_summary:
        try {//from ww w.j a  v a 2 s  .c om
            Intent powerSummary = new Intent(Intent.ACTION_POWER_USAGE_SUMMARY);
            ResolveInfo resolveInfo = getPackageManager().resolveActivity(powerSummary, 0);
            if (resolveInfo != null) {
                startActivity(powerSummary);
            }
            // TODO: else show dialog
        } catch (ActivityNotFoundException e) {
            e.printStackTrace();
        }
        return true;
    case R.id.action_settings:
        Answers.getInstance().logContentView(new ContentViewEvent().putContentName("Enters settings page")
                .putContentType("Page visit").putContentId("page-settings"));
        startActivity(new Intent(this, SettingsActivity.class));
        return true;
    case R.id.action_rating:
        Answers.getInstance()
                .logContentView(new ContentViewEvent().putContentName("Enters Google Play Store to rate")
                        .putContentType("Page visit").putContentId("page-store"));
        try {
            startActivity(
                    new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.hmatalonga.greenhub")));
        } catch (ActivityNotFoundException e) {
            startActivity(new Intent(Intent.ACTION_VIEW,
                    Uri.parse("http://play.google.com/store/apps/details?id=com.hmatalonga.greenhub")));
        }
        return true;
    }

    return false;
}

From source file:co.lemonlabs.android.slidingdebugmenu.SlidingDebugMenu.java

@SuppressWarnings("ConstantConditions")
@Override/*from w ww  .j a v  a  2s .c o m*/
public void onClick(View v) {
    final int id = v.getId();
    Context context = getContext();

    if (id == R.id.sdm__settings_developer) {
        // open dev settings
        Intent devIntent = new Intent(Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS);
        ResolveInfo resolveInfo = context.getPackageManager().resolveActivity(devIntent, 0);
        if (resolveInfo != null)
            context.startActivity(devIntent);
        else
            Toast.makeText(context, "Developer settings not available on device", Toast.LENGTH_SHORT).show();

    } else if (id == R.id.sdm__settings_battery) {
        // try to find an app to handle battery settings
        Intent batteryIntent = new Intent(Intent.ACTION_POWER_USAGE_SUMMARY);
        ResolveInfo resolveInfo = context.getPackageManager().resolveActivity(batteryIntent, 0);
        if (resolveInfo != null)
            context.startActivity(batteryIntent);
        else
            Toast.makeText(context, "No app found to handle power usage intent", Toast.LENGTH_SHORT).show();

    } else if (id == R.id.sdm__settings_drawer) {
        // open android settings
        context.startActivity(new Intent(Settings.ACTION_SETTINGS));

    } else if (id == R.id.sdm__settings_app_info) {
        Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
        intent.setData(Uri.parse("package:" + context.getPackageName()));
        context.startActivity(intent);

    } else if (id == R.id.sdm__settings_uninstall) {
        // open dialog to uninstall app
        Uri packageURI = Uri.parse("package:" + context.getPackageName());
        Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageURI);
        context.startActivity(uninstallIntent);
    }
}

From source file:com.brewcrewfoo.performance.fragments.BatteryInfo.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup root, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.battery_info, root, false);

    mbattery_percent = (TextView) view.findViewById(R.id.batt_percent);
    mbattery_volt = (TextView) view.findViewById(R.id.batt_volt);
    mbattery_status = (TextView) view.findViewById(R.id.batt_status);
    mBattIcon = (ImageView) view.findViewById(R.id.batt_icon);

    if (new File(BAT_VOLT_PATH).exists()) {
        int volt = Integer.parseInt(Helpers.readOneLine(BAT_VOLT_PATH));
        if (volt > 5000)
            volt = (int) Math.round(volt / 1000.0);// in microvolts
        mbattery_volt.setText(volt + " mV");
        mBattIcon.setVisibility(ImageView.GONE);
        mbattery_volt.setVisibility(TextView.VISIBLE);
        mbattery_volt.setOnClickListener(new View.OnClickListener() {
            @Override/*  w  w  w  .jav a2s. co  m*/
            public void onClick(View view) {
                Intent powerUsageIntent = new Intent(Intent.ACTION_POWER_USAGE_SUMMARY);
                if (powerUsageIntent.resolveActivity(context.getPackageManager()) != null)
                    startActivity(powerUsageIntent);
            }
        });
        mbattery_volt.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {
                mBattIcon.setVisibility(ImageView.VISIBLE);
                mbattery_volt.setVisibility(TextView.GONE);
                return true;
            }
        });
    } else {
        mBattIcon.setVisibility(ImageView.VISIBLE);
        mbattery_volt.setVisibility(TextView.GONE);
        mBattIcon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                try {
                    Intent powerUsageIntent = new Intent(Intent.ACTION_POWER_USAGE_SUMMARY);
                    startActivity(powerUsageIntent);
                } catch (Exception e) {
                }
            }
        });
    }

    SeekBar mBlxSlider = (SeekBar) view.findViewById(R.id.blx_slider);
    if (new File(BLX_PATH).exists()) {
        no_settings = false;
        mBlxSlider.setMax(100);

        mBlxVal = (TextView) view.findViewById(R.id.blx_val);
        mBlxVal.setText(getString(R.string.blx_title) + " " + Helpers.readOneLine(BLX_PATH) + "%");

        mBlxSlider.setProgress(Integer.parseInt(Helpers.readOneLine(BLX_PATH)));
        mBlxSlider.setOnSeekBarChangeListener(this);
        Switch mSetOnBoot = (Switch) view.findViewById(R.id.blx_sob);
        mSetOnBoot.setChecked(mPreferences.getBoolean(BLX_SOB, false));
        mSetOnBoot.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton v, boolean checked) {
                final SharedPreferences.Editor editor = mPreferences.edit();
                editor.putBoolean(BLX_SOB, checked);
                if (checked) {
                    editor.putInt(PREF_BLX, Integer.parseInt(Helpers.readOneLine(BLX_PATH)));
                }
                editor.commit();
            }
        });
    } else {
        LinearLayout mpart = (LinearLayout) view.findViewById(R.id.blx_layout);
        mpart.setVisibility(LinearLayout.GONE);
    }
    mFastChargePath = Helpers.fastcharge_path();
    if (mFastChargePath != null) {
        no_settings = false;
        mFastchargeOnBoot = (Switch) view.findViewById(R.id.fastcharge_sob);
        mFastchargeOnBoot.setChecked(
                mPreferences.getBoolean(PREF_FASTCHARGE, Helpers.readOneLine(mFastChargePath).equals("1")));
        mFastchargeOnBoot.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton v, boolean checked) {
                mPreferences.edit().putBoolean(PREF_FASTCHARGE, checked).apply();
                final NotificationManager nm = (NotificationManager) context
                        .getSystemService(Context.NOTIFICATION_SERVICE);
                if (checked) {
                    new CMDProcessor().su.runWaitFor("busybox echo 1 > " + mFastChargePath);
                    Notification n = new Notification.Builder(context)
                            .setContentTitle(context.getText(R.string.app_name))
                            .setContentText(context.getText(R.string.fast_charge_notification_title))
                            .setTicker(context.getText(R.string.fast_charge_notification_title))
                            .setSmallIcon(R.drawable.ic_fastcharge).setWhen(System.currentTimeMillis())
                            .getNotification();
                    //n.flags = Notification.FLAG_NO_CLEAR;
                    nm.notify(1337, n);
                } else {
                    new CMDProcessor().su.runWaitFor("busybox echo 0 > " + mFastChargePath);
                    nm.cancel(1337);
                }
            }
        });
    } else {
        LinearLayout mpart = (LinearLayout) view.findViewById(R.id.fastcharge_layout);
        mpart.setVisibility(LinearLayout.GONE);
    }
    if (no_settings) {
        LinearLayout ns = (LinearLayout) view.findViewById(R.id.no_settings);
        ns.setVisibility(LinearLayout.VISIBLE);
    }

    return view;
}

From source file:mx.klozz.xperience.tweaker.fragments.BatteryInfo.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup root, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.battery_info, root, false);

    mBattery_Percent = (TextView) view.findViewById(R.id.battery_percent);
    mBattery_volt = (TextView) view.findViewById(R.id.battery_volt);
    mBattery_Status = (TextView) view.findViewById(R.id.battery_status);
    mBatteryIcon = (ImageView) view.findViewById(R.id.battery_icon);

    //Checamos si existe algo relacionado con la direccion de voltajes
    if (new File(BAT_VOLT_PATH).exists()) {
        int volt = Integer.parseInt(Helpers.LeerUnaLinea(BAT_VOLT_PATH));//vemos si existe el directorio
        if (volt > 5000)
            volt = (int) Math.round(volt / 1000.0);//Convertimos a microvolts

        mBattery_volt.setText(volt + " mV");//Hacemos visible los datos
        mBatteryIcon.setVisibility(ImageView.GONE);
        mBattery_volt.setVisibility(TextView.VISIBLE);
        mBattery_volt.setOnClickListener(new View.OnClickListener() {
            @Override//w ww. j av  a 2 s .  c om
            public void onClick(View view) {
                Intent powerUsageIntent = new Intent(Intent.ACTION_POWER_USAGE_SUMMARY);
                if (powerUsageIntent.resolveActivity(context.getPackageManager()) != null)
                    startActivity(powerUsageIntent);
            }
        });
        mBattery_volt.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {
                mBatteryIcon.setVisibility(ImageView.VISIBLE);
                mBattery_volt.setVisibility(TextView.GONE);
                return true;
            }
        });
    } else {
        mBatteryIcon.setVisibility(ImageView.VISIBLE);
        mBattery_volt.setVisibility(TextView.GONE);
        mBatteryIcon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                try {
                    Intent powerUsageIntent = new Intent(Intent.ACTION_POWER_USAGE_SUMMARY);
                    startActivity(powerUsageIntent);
                } catch (Exception e) {
                }
            }
        });
    }

    mFastChargePath = Helpers.fastcharge_path();
    if (mFastChargePath != null) {
        no_settings = false;
        mFastChargeOnBoot = (Switch) view.findViewById(R.id.fastcharge_sob);
        mFastChargeOnBoot.setChecked(
                mPreferences.getBoolean(PREF_FASTCHARGE, Helpers.LeerUnaLinea(mFastChargePath).equals("1")));
        mFastChargeOnBoot.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton v, boolean checked) {
                mPreferences.edit().putBoolean(PREF_FASTCHARGE, checked).apply();
                final NotificationManager NM = (NotificationManager) context
                        .getSystemService(Context.NOTIFICATION_SERVICE);
                if (checked) {
                    new CMDProcessor().su.runWaitFor("busybox exho 1 > " + mFastChargePath);
                    Notification N = new Notification.Builder(context)
                            .setContentTitle(context.getText(R.string.app_name))
                            .setContentText(context.getText(R.string.fast_charge_notification_title))
                            .setTicker(context.getText(R.string.fast_charge_notification_title))
                            .setSmallIcon(R.drawable.ic_fastcharge).setWhen(System.currentTimeMillis())
                            .getNotification();
                    NM.notify(1337, N);
                } else {
                    new CMDProcessor().su.runWaitFor("busybox echo 0 > " + mFastChargePath);
                    NM.cancel(1337);

                }
            }

        });
    } else {
        LinearLayout mPart = (LinearLayout) view.findViewById(R.id.fastcharge_layout);
        mPart.setVisibility(LinearLayout.GONE);
    }
    if (no_settings) {
        LinearLayout NS = (LinearLayout) view.findViewById(R.id.no_settings);
        NS.setVisibility(LinearLayout.VISIBLE);
    }
    return view;
}