Back to project page groceryviewer.
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.
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); } }