use of android.content.Context in project platform_frameworks_base by android.
the class BatteryInfo method bindHistory.
public void bindHistory(final UsageView view, BatteryDataParser... parsers) {
BatteryDataParser parser = new BatteryDataParser() {
SparseIntArray points = new SparseIntArray();
@Override
public void onParsingStarted(long startTime, long endTime) {
timePeriod = endTime - startTime - remainingTimeUs / 1000;
view.clearPaths();
view.configureGraph((int) (endTime - startTime), 100, remainingTimeUs != 0, mCharging);
}
@Override
public void onDataPoint(long time, HistoryItem record) {
points.put((int) time, record.batteryLevel);
}
@Override
public void onDataGap() {
if (points.size() > 1) {
view.addPath(points);
}
points.clear();
}
@Override
public void onParsingDone() {
if (points.size() > 1) {
view.addPath(points);
}
}
};
BatteryDataParser[] parserList = new BatteryDataParser[parsers.length + 1];
for (int i = 0; i < parsers.length; i++) {
parserList[i] = parsers[i];
}
parserList[parsers.length] = parser;
parse(mStats, remainingTimeUs, parserList);
final Context context = view.getContext();
String timeString = context.getString(R.string.charge_length_format, Formatter.formatShortElapsedTime(context, timePeriod));
String remaining = "";
if (remainingTimeUs != 0) {
remaining = context.getString(R.string.remaining_length_format, Formatter.formatShortElapsedTime(context, remainingTimeUs / 1000));
}
view.setBottomLabels(new CharSequence[] { timeString, remaining });
}
use of android.content.Context in project platform_frameworks_base by android.
the class LocalBluetoothManager method getInstance.
public static synchronized LocalBluetoothManager getInstance(Context context, BluetoothManagerCallback onInitCallback) {
if (sInstance == null) {
LocalBluetoothAdapter adapter = LocalBluetoothAdapter.getInstance();
if (adapter == null) {
return null;
}
// This will be around as long as this process is
Context appContext = context.getApplicationContext();
sInstance = new LocalBluetoothManager(adapter, appContext);
if (onInitCallback != null) {
onInitCallback.onBluetoothManagerInitialized(appContext, sInstance);
}
}
return sInstance;
}
use of android.content.Context in project platform_frameworks_base by android.
the class TaskView method onClick.
/**** View.OnClickListener Implementation ****/
@Override
public void onClick(final View v) {
if (mIsDisabledInSafeMode) {
Context context = getContext();
String msg = context.getString(R.string.recents_launch_disabled_message, mTask.title);
if (mDisabledAppToast != null) {
mDisabledAppToast.cancel();
}
mDisabledAppToast = Toast.makeText(context, msg, Toast.LENGTH_SHORT);
mDisabledAppToast.show();
return;
}
boolean screenPinningRequested = false;
if (v == mActionButtonView) {
// Reset the translation of the action button before we animate it out
mActionButtonView.setTranslationZ(0f);
screenPinningRequested = true;
}
EventBus.getDefault().send(new LaunchTaskEvent(this, mTask, null, INVALID_STACK_ID, screenPinningRequested));
MetricsLogger.action(v.getContext(), MetricsEvent.ACTION_OVERVIEW_SELECT, mTask.key.getComponent().toString());
}
use of android.content.Context in project platform_frameworks_base by android.
the class GlobalScreenshot method doInBackground.
@Override
protected Void doInBackground(Void... params) {
if (isCancelled()) {
return null;
}
// By default, AsyncTask sets the worker thread to have background thread priority, so bump
// it back up so that we save a little quicker.
Process.setThreadPriority(Process.THREAD_PRIORITY_FOREGROUND);
Context context = mParams.context;
Bitmap image = mParams.image;
Resources r = context.getResources();
try {
// Create screenshot directory if it doesn't exist
mScreenshotDir.mkdirs();
// media provider uses seconds for DATE_MODIFIED and DATE_ADDED, but milliseconds
// for DATE_TAKEN
long dateSeconds = mImageTime / 1000;
// Save
OutputStream out = new FileOutputStream(mImageFilePath);
image.compress(Bitmap.CompressFormat.PNG, 100, out);
out.flush();
out.close();
// Save the screenshot to the MediaStore
ContentValues values = new ContentValues();
ContentResolver resolver = context.getContentResolver();
values.put(MediaStore.Images.ImageColumns.DATA, mImageFilePath);
values.put(MediaStore.Images.ImageColumns.TITLE, mImageFileName);
values.put(MediaStore.Images.ImageColumns.DISPLAY_NAME, mImageFileName);
values.put(MediaStore.Images.ImageColumns.DATE_TAKEN, mImageTime);
values.put(MediaStore.Images.ImageColumns.DATE_ADDED, dateSeconds);
values.put(MediaStore.Images.ImageColumns.DATE_MODIFIED, dateSeconds);
values.put(MediaStore.Images.ImageColumns.MIME_TYPE, "image/png");
values.put(MediaStore.Images.ImageColumns.WIDTH, mImageWidth);
values.put(MediaStore.Images.ImageColumns.HEIGHT, mImageHeight);
values.put(MediaStore.Images.ImageColumns.SIZE, new File(mImageFilePath).length());
Uri uri = resolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
// Create a share intent
String subjectDate = DateFormat.getDateTimeInstance().format(new Date(mImageTime));
String subject = String.format(SCREENSHOT_SHARE_SUBJECT_TEMPLATE, subjectDate);
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("image/png");
sharingIntent.putExtra(Intent.EXTRA_STREAM, uri);
sharingIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
// Create a share action for the notification
PendingIntent chooseAction = PendingIntent.getBroadcast(context, 0, new Intent(context, GlobalScreenshot.TargetChosenReceiver.class), PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT);
Intent chooserIntent = Intent.createChooser(sharingIntent, null, chooseAction.getIntentSender()).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent shareAction = PendingIntent.getActivity(context, 0, chooserIntent, PendingIntent.FLAG_CANCEL_CURRENT);
Notification.Action.Builder shareActionBuilder = new Notification.Action.Builder(R.drawable.ic_screenshot_share, r.getString(com.android.internal.R.string.share), shareAction);
mNotificationBuilder.addAction(shareActionBuilder.build());
// Create a delete action for the notification
PendingIntent deleteAction = PendingIntent.getBroadcast(context, 0, new Intent(context, GlobalScreenshot.DeleteScreenshotReceiver.class).putExtra(GlobalScreenshot.SCREENSHOT_URI_ID, uri.toString()), PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT);
Notification.Action.Builder deleteActionBuilder = new Notification.Action.Builder(R.drawable.ic_screenshot_delete, r.getString(com.android.internal.R.string.delete), deleteAction);
mNotificationBuilder.addAction(deleteActionBuilder.build());
mParams.imageUri = uri;
mParams.image = null;
mParams.errorMsgResId = 0;
} catch (Exception e) {
// IOException/UnsupportedOperationException may be thrown if external storage is not
// mounted
mParams.clearImage();
mParams.errorMsgResId = R.string.screenshot_failed_to_save_text;
}
// Recycle the bitmap data
if (image != null) {
image.recycle();
}
return null;
}
use of android.content.Context in project platform_frameworks_base by android.
the class DemoModeFragment method onCreatePreferences.
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
Context context = getContext();
mEnabledSwitch = new SwitchPreference(context);
mEnabledSwitch.setTitle(R.string.enable_demo_mode);
mEnabledSwitch.setOnPreferenceChangeListener(this);
mOnSwitch = new SwitchPreference(context);
mOnSwitch.setTitle(R.string.show_demo_mode);
mOnSwitch.setEnabled(false);
mOnSwitch.setOnPreferenceChangeListener(this);
PreferenceScreen screen = getPreferenceManager().createPreferenceScreen(context);
screen.addPreference(mEnabledSwitch);
screen.addPreference(mOnSwitch);
setPreferenceScreen(screen);
updateDemoModeEnabled();
updateDemoModeOn();
ContentResolver contentResolver = getContext().getContentResolver();
contentResolver.registerContentObserver(Settings.Global.getUriFor(DemoMode.DEMO_MODE_ALLOWED), false, mDemoModeObserver);
contentResolver.registerContentObserver(Settings.Global.getUriFor(DEMO_MODE_ON), false, mDemoModeObserver);
setHasOptionsMenu(true);
}
Aggregations