Example usage for android.app Activity getContentResolver

List of usage examples for android.app Activity getContentResolver

Introduction

In this page you can find the example usage for android.app Activity getContentResolver.

Prototype

@Override
    public ContentResolver getContentResolver() 

Source Link

Usage

From source file:org.sufficientlysecure.keychain.ui.LogDisplayFragment.java

private void shareLog() {

    Activity activity = getActivity();
    if (activity == null) {
        return;/*  w w  w .ja v  a  2 s . c  om*/
    }

    String log = mResult.getLog().getPrintableOperationLog(getResources(), 0);

    // if there is no log temp file yet, create one
    if (mLogTempFile == null) {
        mLogTempFile = TemporaryFileProvider.createFile(getActivity(), "openkeychain_log.txt", "text/plain");
        try {
            OutputStream outputStream = activity.getContentResolver().openOutputStream(mLogTempFile);
            outputStream.write(log.getBytes());
        } catch (IOException e) {
            Notify.create(activity, R.string.error_log_share_internal, Style.ERROR).show();
            return;
        }
    }

    ShareLogDialogFragment shareLogDialog = ShareLogDialogFragment.newInstance(mLogTempFile);
    shareLogDialog.show(getActivity().getSupportFragmentManager(), "shareLogDialog");

}

From source file:biz.wiz.android.wallet.ui.TransactionsListFragment.java

@Override
public void onAttach(final Activity activity) {
    super.onAttach(activity);

    this.activity = (AbstractWalletActivity) activity;
    this.application = (WalletApplication) activity.getApplication();
    this.config = application.getConfiguration();
    this.wallet = application.getWallet();
    this.resolver = activity.getContentResolver();
    this.loaderManager = getLoaderManager();
}

From source file:com.rjfun.cordova.sms.SMSPlugin.java

private PluginResult stopWatch(CallbackContext callbackContext) {
    Log.d(LOGTAG, ACTION_STOP_WATCH);/*from  ww w  .j a  v  a 2s . c om*/
    Activity ctx = this.cordova.getActivity();
    if (this.mReceiver != null) {
        ctx.unregisterReceiver(this.mReceiver);
        this.mReceiver = null;
        Log.d(LOGTAG, "broadcast receiver unregistered");
    }
    if (this.mObserver != null) {
        ctx.getContentResolver().unregisterContentObserver(this.mObserver);
        this.mObserver = null;
        Log.d(LOGTAG, "sms inbox observer unregistered");
    }
    if (callbackContext != null) {
        callbackContext.success();
    }
    return null;
}

From source file:io.rapidpro.androidchannel.MessageListFragment.java

public void onAttach(android.app.Activity activity) {
    super.onAttach(activity);

    m_receiver = new UpdateReceiver();
    IntentFilter filter = new IntentFilter();
    filter.addCategory(Intent.CATEGORY_DEFAULT);
    activity.registerReceiver(m_receiver, filter);

    getLoaderManager().initLoader(0, null, this);

    // listen to changes to our content provider
    Handler handler = new Handler(activity.getMainLooper());
    m_observer = new MessageObserver(handler);

    ContentResolver cr = activity.getContentResolver();
    cr.registerContentObserver(DBCommandContentProvider.CONTENT_URI, true, m_observer);
}

From source file:com.android.camera.v2.uimanager.ThumbnailManager.java

/**
 * Create a thumbnail manager controller.
 * @param appcontroller controller used to get service for storage.
 * @param activity the current activity.
 * @param parent view group./*from  w w  w.j a  v  a 2 s . c o  m*/
 * @param secureCamera whether the current camera is secure camera or not.
 */
public ThumbnailManager(AppController appcontroller, Activity activity, ViewGroup parent,
        boolean secureCamera) {
    super(activity, parent);
    mIsSecureCamera = secureCamera;
    setFilterEnable(false);
    mStorageService = appcontroller.getAppControllerAdapter().getServices().getStorageService();
    mActivity = activity;
    mContentResolver = activity.getContentResolver();
    mMaiHandler = new Handler(activity.getMainLooper());
    HandlerThread t = new HandlerThread("thumbnail-creation-thread");
    t.start();
    mHandler = new ThumbnailCreatorHandler(t.getLooper());
    mThumbnailAnimation = new ThumbnailAnimation();

    LocalBroadcastManager manager = LocalBroadcastManager.getInstance(mActivity);
    manager.registerReceiver(mUpdatePictureReceiver, mUpdatePictureFilter);
    mActivity.registerReceiver(mIpoShutdownReceiver, mIpoShutdownFilter);

    mIntent = activity.getIntent();
    String action = null;
    if (mIntent != null) {
        action = mIntent.getAction();
    }
    if (MediaStore.ACTION_IMAGE_CAPTURE.equals(action) || MediaStore.ACTION_VIDEO_CAPTURE.equals(action)
            || CameraUtil.ACTION_STEREO3D.equals(action)) {
        mShownByIntent = false;
    }
}

From source file:de.k3b.android.androFotoFinder.imagedetail.ImagePagerAdapterFromCursor.java

/**
 * Initiates a database requery in a background thread. onLoadFinished() is called when done.
 *//*from  w ww  .j av  a  2 s .c om*/
private void requery(final Activity context, final String[] sqlProjection, final String from,
        final String sqlWhereStatement, final String sqlSortOrder, final String... sqlWhereParameters) {

    /*
     * Initializes the CursorLoader. The MY_LOADER_ID value is eventually passed
     * to onCreateLoader().
     */

    if (SYNC) {
        // for debugging
        Cursor result = context.getContentResolver().query(Uri.parse(from), // Table to query
                sqlProjection, // Projection to return
                sqlWhereStatement, // No selection clause
                sqlWhereParameters, // No selection arguments
                sqlSortOrder // Default sort order
        );
        onLoadFinished(result);
    } else {
        final int currentLoaderId = ++MY_LOADER_ID;
        context.getLoaderManager().initLoader(currentLoaderId, null,
                new LoaderManager.LoaderCallbacks<Cursor>() {

                    @Override
                    public Loader<Cursor> onCreateLoader(int loaderID, Bundle args) {
                        if (loaderID == currentLoaderId) {
                            // Returns a new CursorLoader
                            return new CursorLoader(context, // Parent activity context
                                    Uri.parse(from), // Table to query
                                    sqlProjection, // Projection to return
                                    sqlWhereStatement, // No selection clause
                                    sqlWhereParameters, // No selection arguments
                                    sqlSortOrder // Default sort order
                            );
                        }
                        return null;
                    }

                    @Override
                    public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
                        ImagePagerAdapterFromCursor.this.onLoadFinished(cursor);
                    }

                    @Override
                    public void onLoaderReset(Loader<Cursor> loader) {
                        ImagePagerAdapterFromCursor.this.onLoadFinished(null);
                    }
                });
    }
}

From source file:net.abcdroid.devfest12.ui.SessionsFragment.java

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);
    if (!(activity instanceof Callbacks)) {
        throw new ClassCastException("Activity must implement fragment's callbacks.");
    }//  ww  w  .  j  av  a 2s  . co m

    mCallbacks = (Callbacks) activity;
    activity.getContentResolver().registerContentObserver(ScheduleContract.Sessions.CONTENT_URI, true,
            mObserver);
}

From source file:systems.soapbox.ombuds.client.ui.WalletTransactionsFragment.java

@Override
public void onAttach(final Activity activity) {
    super.onAttach(activity);

    this.activity = (AbstractWalletActivity) activity;
    this.application = (WalletApplication) activity.getApplication();
    this.config = application.getConfiguration();
    this.wallet = application.getWallet();
    this.resolver = activity.getContentResolver();
    this.loaderManager = getLoaderManager();
    this.devicePolicyManager = (DevicePolicyManager) application
            .getSystemService(Context.DEVICE_POLICY_SERVICE);
}

From source file:com.midisheetmusicmemo.FileUri.java

/** Return the file contents as a byte array.
 *  If any IO error occurs, return null.
 *//*from w  w w.j av  a2 s  . co m*/
public byte[] getData(Activity activity) {
    try {
        byte[] data;
        int totallen, len, offset;

        // First, determine the file length
        data = new byte[4096];
        InputStream file;
        String uriString = uri.toString();
        if (uriString.startsWith("file:///android_asset/")) {
            AssetManager asset = activity.getResources().getAssets();
            String filepath = uriString.replace("file:///android_asset/", "");
            file = asset.open(filepath);
        } else if (uriString.startsWith("content://")) {
            ContentResolver resolver = activity.getContentResolver();
            file = resolver.openInputStream(uri);
        } else {
            file = new FileInputStream(uri.getPath());
        }
        totallen = 0;
        len = file.read(data, 0, 4096);
        while (len > 0) {
            totallen += len;
            len = file.read(data, 0, 4096);
        }
        file.close();

        // Now read in the data
        offset = 0;
        data = new byte[totallen];

        if (uriString.startsWith("file:///android_asset/")) {
            AssetManager asset = activity.getResources().getAssets();
            String filepath = uriString.replace("file:///android_asset/", "");
            file = asset.open(filepath);
        } else if (uriString.startsWith("content://")) {
            ContentResolver resolver = activity.getContentResolver();
            file = resolver.openInputStream(uri);
        } else {
            file = new FileInputStream(uri.getPath());
        }
        while (offset < totallen) {
            len = file.read(data, offset, totallen - offset);
            if (len <= 0) {
                throw new MidiFileException("Error reading midi file", offset);
            }
            offset += len;
        }
        file.close();
        return data;
    } catch (Exception e) {
        return null;
    }
}

From source file:cc.mintcoin.wallet.ui.TransactionsListFragment.java

@Override
public void onAttach(final Activity activity) {
    super.onAttach(activity);

    this.activity = (AbstractWalletActivity) activity;
    this.application = (WalletApplication) activity.getApplication();
    this.config = application.getConfiguration();
    this.wallet = application.getWallet();
    this.nfcManager = (NfcManager) activity.getSystemService(Context.NFC_SERVICE);
    this.resolver = activity.getContentResolver();
    this.loaderManager = getLoaderManager();
}