Android Open Source - PicSync Gallery Observer






From Project

Back to project page PicSync.

License

The source code is released under:

Apache License

If you think the Android project PicSync listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.darrenmowat.gdcu.service;
/*ww  w.j a  v a2s.com*/
import java.io.File;

import android.content.Context;
import android.content.Intent;
import android.database.ContentObserver;
import android.database.Cursor;
import android.net.Uri;
import android.provider.MediaStore.MediaColumns;
import android.util.Log;

import com.darrenmowat.gdcu.service.helpers.Media;

public class GalleryObserver extends ContentObserver {

  private Context context;
  private Uri BASE_URI;

  public GalleryObserver(Context context, Uri base) {
    super(null);
    this.context = context;
    this.BASE_URI = base;
  }

  @Override
  public void onChange(boolean selfChange) {
    super.onChange(selfChange);
    Media media = readFromMediaStore(context, BASE_URI);
    if (media == null) {
      log("Media returned from database was null");
      return;
    }

    Intent service = new Intent(context, MediaService.class);
    context.startService(service);
  }

  private static final String[] projection = { MediaColumns.DATA, MediaColumns.MIME_TYPE };
  private static final String sortorder = MediaColumns.DATE_ADDED + " DESC LIMIT 1";

  private Media readFromMediaStore(Context context, Uri uri) {
    Cursor cursor = context.getContentResolver().query(uri, projection, null, null, sortorder);
    Media media = null;
    if (cursor.moveToNext()) {
      int dataColumn = cursor.getColumnIndexOrThrow(MediaColumns.DATA);
      String filePath = cursor.getString(dataColumn);
      int mimeTypeColumn = cursor.getColumnIndexOrThrow(MediaColumns.MIME_TYPE);
      String mimeType = cursor.getString(mimeTypeColumn);
      media = new Media(new File(filePath), mimeType);
    }
    cursor.close();
    return media;
  }

  private void log(String msg) {
    Log.v("GDCU::GalleryObserver", msg);
  }

}




Java Source Code List

com.darrenmowat.gdcu.GDCU.java
com.darrenmowat.gdcu.Keys.java
com.darrenmowat.gdcu.activity.AuthActivity.java
com.darrenmowat.gdcu.activity.RenameFolderActivity.java
com.darrenmowat.gdcu.activity.SettingsActivity.java
com.darrenmowat.gdcu.activity.WebviewActivity.java
com.darrenmowat.gdcu.data.Database.java
com.darrenmowat.gdcu.data.Preferences.java
com.darrenmowat.gdcu.drive.DriveApi.java
com.darrenmowat.gdcu.otto.DataBus.java
com.darrenmowat.gdcu.otto.UploadStatusEventProducer.java
com.darrenmowat.gdcu.otto.UploadStatusEvent.java
com.darrenmowat.gdcu.security.PackageSecurityException.java
com.darrenmowat.gdcu.security.PackageSecurity.java
com.darrenmowat.gdcu.service.GalleryAlarmListener.java
com.darrenmowat.gdcu.service.GalleryObserver.java
com.darrenmowat.gdcu.service.MediaService.java
com.darrenmowat.gdcu.service.MediaThread.java
com.darrenmowat.gdcu.service.Notifier.java
com.darrenmowat.gdcu.service.ServiceUtils.java
com.darrenmowat.gdcu.service.UploadService.java
com.darrenmowat.gdcu.service.UploadThread.java
com.darrenmowat.gdcu.service.helpers.CloudSyncer.java
com.darrenmowat.gdcu.service.helpers.Media.java
com.darrenmowat.gdcu.service.helpers.ServiceIntents.java
com.darrenmowat.gdcu.service.helpers.ThreadCallbacks.java
com.darrenmowat.gdcu.tasks.GetTokenTask.java
com.darrenmowat.gdcu.tasks.RenameFolderTask.java
com.darrenmowat.gdcu.ui.ProgressDialogFragment.java
com.darrenmowat.gdcu.utils.HexConversions.java
com.darrenmowat.gdcu.utils.MD5Utils.java
com.darrenmowat.gdcu.utils.Preconditions.java