Search in sources :

Example 66 with Context

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 });
}
Also used : Context(android.content.Context) SparseIntArray(android.util.SparseIntArray) HistoryItem(android.os.BatteryStats.HistoryItem)

Example 67 with Context

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;
}
Also used : Context(android.content.Context)

Example 68 with Context

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());
}
Also used : Context(android.content.Context) LaunchTaskEvent(com.android.systemui.recents.events.activity.LaunchTaskEvent)

Example 69 with Context

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;
}
Also used : Context(android.content.Context) ContentValues(android.content.ContentValues) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) Uri(android.net.Uri) Date(java.util.Date) Notification(android.app.Notification) ContentResolver(android.content.ContentResolver) Bitmap(android.graphics.Bitmap) FileOutputStream(java.io.FileOutputStream) Resources(android.content.res.Resources) PendingIntent(android.app.PendingIntent) File(java.io.File)

Example 70 with Context

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);
}
Also used : Context(android.content.Context) PreferenceScreen(android.support.v7.preference.PreferenceScreen) SwitchPreference(android.support.v14.preference.SwitchPreference) ContentResolver(android.content.ContentResolver)

Aggregations

Context (android.content.Context)3233 Intent (android.content.Intent)676 View (android.view.View)400 Test (org.junit.Test)346 BroadcastReceiver (android.content.BroadcastReceiver)338 IntentFilter (android.content.IntentFilter)301 TextView (android.widget.TextView)258 Resources (android.content.res.Resources)226 PendingIntent (android.app.PendingIntent)188 PackageManager (android.content.pm.PackageManager)164 File (java.io.File)156 IOException (java.io.IOException)150 LayoutInflater (android.view.LayoutInflater)139 ImageView (android.widget.ImageView)135 Drawable (android.graphics.drawable.Drawable)128 Uri (android.net.Uri)115 RemoteException (android.os.RemoteException)102 ArrayList (java.util.ArrayList)102 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)101 Bundle (android.os.Bundle)95