Android Open Source - groceryviewer Grocery Viewer Utils






From Project

Back to project page groceryviewer.

License

The source code is released under:

GNU General Public License

If you think the Android project groceryviewer 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.github.knrajago.groceryviewer.utils;
//from   w  w  w.j a  v a2  s . c om
import static com.github.knrajago.groceryviewer.constants.GroceryViewerConstants.CREDENTIAL_KEY;
import static com.github.knrajago.groceryviewer.constants.GroceryViewerConstants.APPLICATION_SHARD_TAG;
import static com.github.knrajago.groceryviewer.constants.GroceryViewerConstants.USER_NAME_KEY;
import static com.github.knrajago.groceryviewer.constants.GroceryViewerConstants.USER_TYPE_KEY;

import android.content.Context;
import android.content.SharedPreferences;

import com.google.api.client.extensions.android.http.AndroidHttp;
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential;
import com.google.api.client.json.gson.GsonFactory;
import com.google.api.services.drive.Drive;

public class GroceryViewerUtils {
  public static void setCredentials(Context pContext, GoogleCredential pCredential) {
    SharedPreferences shrdPref = pContext.getSharedPreferences(APPLICATION_SHARD_TAG, Context.MODE_PRIVATE);
    SharedPreferences.Editor edtr = shrdPref.edit();
    edtr.putString(CREDENTIAL_KEY, pCredential.getAccessToken());
    edtr.commit();
  }
  
  public static GoogleCredential getCredentials(Context pContext) {
    SharedPreferences shrdPref = pContext.getSharedPreferences(APPLICATION_SHARD_TAG, Context.MODE_PRIVATE);
    String token = shrdPref.getString(CREDENTIAL_KEY, "");
    GoogleCredential cred = new GoogleCredential();
    cred.setAccessToken(token);
    return cred;
  }
  
  public static Drive getDriveService(GoogleAccountCredential credential) {
      return new Drive.Builder(AndroidHttp.newCompatibleTransport(), new GsonFactory(), credential)
          .build();
   }
  
  public static void setUserName(Context pContext, String pUserName) {
    SharedPreferences shrdPref = pContext.getSharedPreferences(APPLICATION_SHARD_TAG, Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = shrdPref.edit();
    editor.putString(USER_NAME_KEY, pUserName);
    editor.commit();
  }
  
  public static String getUserName(Context pContext) {
    SharedPreferences shrdPref = pContext.getSharedPreferences(APPLICATION_SHARD_TAG, Context.MODE_PRIVATE);
    return shrdPref.getString(USER_NAME_KEY, null);
  }
  
  public static void setAccountType(Context pContext, String pAccountType) {
    SharedPreferences shrdPref = pContext.getSharedPreferences(APPLICATION_SHARD_TAG, Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = shrdPref.edit();
    editor.putString(USER_TYPE_KEY, pAccountType);
    editor.commit();
  }
  
  public static String getAccountType(Context pContext) {
    SharedPreferences shrdPref = pContext.getSharedPreferences(APPLICATION_SHARD_TAG, Context.MODE_PRIVATE);
    return shrdPref.getString(USER_TYPE_KEY, null);
  }
  
    public static boolean isUserNotSetup(Context pContext) {
      String userName = getUserName(pContext);
      String appType = getAccountType(pContext);
      return (userName == null) || (appType == null);
    }
    
    

}




Java Source Code List

android.UnusedStub.java
com.github.knrajago.groceryviewer.GroceryViewerActivity.java
com.github.knrajago.groceryviewer.constants.GroceryViewerConstants.java
com.github.knrajago.groceryviewer.listadapters.GroceryListAdapter.java
com.github.knrajago.groceryviewer.localdb.GroceryListHelper.java
com.github.knrajago.groceryviewer.observers.GroceryViewerObserver.java
com.github.knrajago.groceryviewer.providers.GroceryViewerContentProvider.java
com.github.knrajago.groceryviewer.services.GroceryViewerSyncService.java
com.github.knrajago.groceryviewer.syncadapters.GoogleSpreadsheetRefresher.java
com.github.knrajago.groceryviewer.threadedutils.GoogleAuthTokenRetriever.java
com.github.knrajago.groceryviewer.utils.GroceryViewerUtils.java