List of usage examples for android.app Activity getApplicationContext
@Override
public Context getApplicationContext()
From source file:com.android.launcher3.Utilities.java
private static void savePic(Bitmap b, String strFileName, Activity activity) { FileOutputStream fos;/*from ww w .j a v a 2s . co m*/ try { fos = new FileOutputStream(strFileName); b.compress(Bitmap.CompressFormat.PNG, 90, fos); fos.flush(); fos.close(); Toast.makeText(activity.getApplicationContext(), "Screenshot Saved", Toast.LENGTH_SHORT).show(); } catch (IOException e) { Log.e("TAG", e.toString()); e.printStackTrace(); } }
From source file:im.neon.activity.CommonActivityUtils.java
/** * Helper method used in {@link #checkPermissions(int, Activity)} to populate the list of the * permissions to be granted (aPermissionsListToBeGranted_out) and the list of the permissions already denied (aPermissionAlreadyDeniedList_out). * * @param aCallingActivity calling activity * @param aPermissionAlreadyDeniedList_out list to be updated with the permissions already denied by the user * @param aPermissionsListToBeGranted_out list to be updated with the permissions to be granted * @param permissionType the permission to be checked * @return true if the permission requires to be granted, false otherwise *//*from w w w .jav a 2s. c o m*/ private static boolean updatePermissionsToBeGranted(final Activity aCallingActivity, List<String> aPermissionAlreadyDeniedList_out, List<String> aPermissionsListToBeGranted_out, final String permissionType) { boolean isRequestPermissionRequested = false; // add permission to be granted aPermissionsListToBeGranted_out.add(permissionType); if (PackageManager.PERMISSION_GRANTED != ContextCompat .checkSelfPermission(aCallingActivity.getApplicationContext(), permissionType)) { isRequestPermissionRequested = true; // add permission to the ones that were already asked to the user if (ActivityCompat.shouldShowRequestPermissionRationale(aCallingActivity, permissionType)) { aPermissionAlreadyDeniedList_out.add(permissionType); } } return isRequestPermissionRequested; }
From source file:com.deltadna.android.sdk.ads.core.AdServiceImpl.java
AdServiceImpl(Activity activity, AdServiceListener listener, String sdkVersion) { Preconditions.checkArg(activity != null, "activity cannot be null"); Preconditions.checkArg(listener != null, "listener cannot be null"); Log.d(BuildConfig.LOG_TAG, "Initialising AdService version " + VERSION); String version = ""; int versionCode = -1; try {/* www . j ava 2 s.com*/ final PackageInfo info = activity.getPackageManager().getPackageInfo(activity.getPackageName(), 0); version = info.versionName; versionCode = info.versionCode; } catch (PackageManager.NameNotFoundException e) { Log.w(BuildConfig.LOG_TAG, "Failed to read app versions", e); } exceptionHandler = new ExceptionHandler(activity.getApplicationContext(), version, versionCode, sdkVersion, BuildConfig.VERSION_NAME); Thread.setDefaultUncaughtExceptionHandler(exceptionHandler); this.activity = activity; this.listener = MainThread.redirect(listener, AdServiceListener.class); metrics = new AdMetrics( activity.getSharedPreferences(Preferences.METRICS.preferencesName(), Context.MODE_PRIVATE)); broadcasts = LocalBroadcastManager.getInstance(activity.getApplicationContext()); adAgentListeners = Collections .unmodifiableSet(new HashSet<>(Arrays.asList(new AgentListener(), new Broadcaster()))); // dynamically load the DebugReceiver try { @SuppressWarnings("unchecked") final Class<BroadcastReceiver> cls = (Class<BroadcastReceiver>) Class .forName("com.deltadna.android.sdk.ads.debug.DebugReceiver"); broadcasts.registerReceiver(cls.newInstance(), Actions.FILTER); Log.d(BuildConfig.LOG_TAG, "DebugReceiver registered"); } catch (ClassNotFoundException ignored) { Log.d(BuildConfig.LOG_TAG, "DebugReceiver not found in classpath"); } catch (IllegalAccessException e) { Log.w(BuildConfig.LOG_TAG, "Failed to load DebugReceiver", e); } catch (InstantiationException e) { Log.w(BuildConfig.LOG_TAG, "Failed to load DebugReceiver", e); } }
From source file:org.cryptsecure.Utility.java
/** * Sets the content view with custom title. This is necessary for a holo * layout where a custom title bar is normally not permitted. * //from w ww .j a va2 s .c o m * @param activity * the activity * @param resIdMainLayout * the res id main layout * @param resIdTitle * the res id title * @return the linear layout */ public static LinearLayout setContentViewWithCustomTitle(Activity activity, int resIdMainLayout, int resIdTitle) { Context context = activity.getApplicationContext(); // Inflate the given layouts LayoutInflater inflaterInfo = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View titleView = (View) inflaterInfo.inflate(resIdTitle, null); View mainView = (View) inflaterInfo.inflate(resIdMainLayout, null); // Own custom title bar // // ATTENTION: // ADD THIS TO THEME <item name="android:windowNoTitle">true</item> activity.requestWindowFeature(Window.FEATURE_NO_TITLE); // We can ONLY disable the original title bar because you cannot combine // HOLO theme with a CUSTOM title bar :( // So we make our own title bar instead! // ALSO REMOVE TITLEBAR FROM APPLICATION AT STARTUP: // ADD TO MANIFEST // android:theme="@android:style/Theme.NoTitleBar" // THE FOLLOWING IS NOT WORKING WITH HOLO // requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); // setContentView(R.layout.activity_main); // getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, // R.layout.title_main); // Create title layout LinearLayout.LayoutParams lpTitle = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); LinearLayout titleLayout = new LinearLayout(context); titleLayout.setOrientation(LinearLayout.VERTICAL); titleLayout.addView(titleView); titleLayout.setLayoutParams(lpTitle); // Create main layout LinearLayout.LayoutParams lpMain = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT); LinearLayout mainLayout = new LinearLayout(context); mainLayout.setOrientation(LinearLayout.VERTICAL); mainLayout.addView(mainView); mainLayout.setLayoutParams(lpMain); // Create root outer layout LinearLayout outerLayout = new LinearLayout(context); outerLayout.setOrientation(LinearLayout.VERTICAL); outerLayout.addView(titleLayout); outerLayout.addView(mainLayout); // outerLayout.setBackgroundColor(Color.rgb(255, 0, 0)); // mainLayout.setBackgroundColor(Color.rgb(0, 255, 0)); // titleLayout.setBackgroundColor(Color.rgb(0, 0, 255)); // lpSectionInnerLeft.setMargins(20, 5, 0, 15); // LinearLayout.LayoutParams lpSectionInnerRight = new // LinearLayout.LayoutParams( // 90, LinearLayout.LayoutParams.WRAP_CONTENT, 0f); // lpSectionInnerRight.setMargins(0, 5, 15, 15); // After setting NO TITLE .. apply the layout activity.setContentView(outerLayout); return mainLayout; }
From source file:im.neon.activity.CommonActivityUtils.java
/** * Restart the application after 100ms//from ww w. jav a 2s .c o m * * @param activity activity */ public static void restartApp(Activity activity) { // clear the preferences SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity); SharedPreferences.Editor editor = preferences.edit(); // use the preference to avoid infinite relaunch on some devices // the culprit activity is restarted when System.exit is called. // so called it once to fix it if (!preferences.getBoolean(RESTART_IN_PROGRESS_KEY, false)) { CommonActivityUtils.displayToast(activity.getApplicationContext(), "Restart the application (low memory)"); Log.e(LOG_TAG, "Kill the application"); editor.putBoolean(RESTART_IN_PROGRESS_KEY, true); editor.commit(); PendingIntent mPendingIntent = PendingIntent.getActivity(activity, 314159, new Intent(activity, LoginActivity.class), PendingIntent.FLAG_CANCEL_CURRENT); // so restart the application after 100ms AlarmManager mgr = (AlarmManager) activity.getSystemService(Context.ALARM_SERVICE); mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 50, mPendingIntent); System.exit(0); } else { Log.e(LOG_TAG, "The application is restarting, please wait !!"); activity.finish(); } }
From source file:im.vector.VectorApp.java
/** * Update the current active activity.//from ww w . j ava 2s. com * It manages the application background / foreground when it is required. * * @param activity the current activity, null if there is no more one. */ private void setCurrentActivity(Activity activity) { Log.d(LOG_TAG, "## setCurrentActivity() : from " + mCurrentActivity + " to " + activity); if (VectorApp.isAppInBackground() && (null != activity)) { Matrix matrixInstance = Matrix.getInstance(activity.getApplicationContext()); // sanity check if (null != matrixInstance) { matrixInstance.refreshPushRules(); } Log.d(LOG_TAG, "The application is resumed"); // display the memory usage when the application is put iun foreground.. CommonActivityUtils.displayMemoryInformation(activity, " app resumed with " + activity); } // wait 2s to check that the application is put in background if (null != getInstance()) { if (null == activity) { getInstance().startActivityTransitionTimer(); } else { getInstance().stopActivityTransitionTimer(); } } else { Log.e(LOG_TAG, "The application is resumed but there is no active instance"); } mCurrentActivity = activity; if (null != mCurrentActivity) { KeyRequestHandler.getSharedInstance().processNextRequest(); } }
From source file:com.sentaroh.android.Utilities.Dialog.SafFileSelectDialogFragment.java
private void initViewWidget() { if (mDebugEnable) Log.v(APPLICATION_TAG, "initViewWidget"); if (mDebugEnable) Log.v(APPLICATION_TAG, "Create=" + mDialogEnableCreate + ", Title=" + mDialogTitle + ", lurl=" + mDialogLocalUuid + ", ldir=" + mDialogLocalDir + ", file name=" + mDialogFileName); mThemeColorList = ThemeUtil.getThemeColorList(getActivity()); mDialog.setContentView(R.layout.file_select_edit_dlg); LinearLayout title_view = (LinearLayout) mDialog.findViewById(R.id.file_select_edit_dlg_title_view); title_view.setBackgroundColor(mThemeColorList.dialog_title_background_color); TextView title = (TextView) mDialog.findViewById(R.id.file_select_edit_dlg_title); title.setTextColor(mThemeColorList.text_color_dialog_title); title.setText(mDialogTitle);//from w w w . j ava 2s. c o m final TextView dlg_msg = (TextView) mDialog.findViewById(R.id.file_select_edit_dlg_msg); final Button btnHome = (Button) mDialog.findViewById(R.id.file_select_edit_dlg_home_dir_btn); btnHome.setTextColor(mThemeColorList.text_color_primary); btnHome.setVisibility(Button.VISIBLE); final Button btnCreate = (Button) mDialog.findViewById(R.id.file_select_edit_dlg_create_btn); btnCreate.setTextColor(mThemeColorList.text_color_primary); final Button btnOk = (Button) mDialog.findViewById(R.id.file_select_edit_dlg_ok_btn); // btnOk.setTextColor(mThemeColorList.text_color_primary); final Button btnCancel = (Button) mDialog.findViewById(R.id.file_select_edit_dlg_cancel_btn); btnCancel.setTextColor(mThemeColorList.text_color_primary); final Button btnRefresh = (Button) mDialog.findViewById(R.id.file_select_edit_dlg_refresh_btn); btnRefresh.setTextColor(mThemeColorList.text_color_primary); LinearLayout ll_dlg_view = (LinearLayout) mDialog.findViewById(R.id.file_select_edit_dlg_view); // LinearLayout ll_dlg_view_filename=(LinearLayout) mDialog.findViewById(R.id.file_select_edit_dlg_view_filename); // LinearLayout ll_dlg_view_create=(LinearLayout) mDialog.findViewById(R.id.file_select_edit_dlg_view_create); // LinearLayout ll_dlg_view_btn=(LinearLayout) mDialog.findViewById(R.id.file_select_edit_dlg_view_btn); ll_dlg_view.setBackgroundColor(mThemeColorList.dialog_msg_background_color); // ll_dlg_view_filename.setBackgroundColor(mThemeColorList.dialog_msg_background_color); // ll_dlg_view_create.setBackgroundColor(mThemeColorList.dialog_msg_background_color); // ll_dlg_view_btn.setBackgroundColor(mThemeColorList.dialog_msg_background_color); final Activity activity = getActivity(); final Context context = activity.getApplicationContext(); if (mDialogEnableCreate) { btnCreate.setVisibility(TextView.VISIBLE); } LinearLayout ll_mp = (LinearLayout) mDialog.findViewById(R.id.file_select_edit_dlg_mp_view); ll_mp.setVisibility(LinearLayout.GONE); mTreeFileListView = (ListView) mDialog.findViewById(android.R.id.list); final EditText filename = (EditText) mDialog.findViewById(R.id.file_select_edit_dlg_file_name); final CustomTextView dir_name = (CustomTextView) mDialog.findViewById(R.id.file_select_edit_dlg_dir_name); filename.setOnKeyListener(new OnKeyListener() { @Override public boolean onKey(View arg0, int keyCode, KeyEvent event) { if (//event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER) { return true; } return false; } }); if (!mDialogSingleSelect) { filename.setVisibility(EditText.GONE); } // if (dirs.size()<=2) v_spacer.setVisibility(TextView.VISIBLE); mTreeFilelistAdapter = new TreeFilelistAdapter(activity, mDialogSingleSelect, true); mTreeFileListView.setAdapter(mTreeFilelistAdapter); // if (mDialogFileOnly) { // mTreeFilelistAdapter.setDirectorySelectable(false); // mTreeFilelistAdapter.setFileSelectable(true); // } // if (mDialogDirOnly) { // mTreeFilelistAdapter.setDirectorySelectable(true); // mTreeFilelistAdapter.setFileSelectable(false); // } ArrayList<TreeFilelistItem> tfl = createLocalFilelist(mDialogFileOnly, mDialogLocalUuid, ""); if (tfl.size() == 0) { tfl.add(new TreeFilelistItem(context.getString(R.string.msgs_file_select_edit_dir_empty))); } else { mTreeFilelistAdapter.setDataList(tfl); if (!mDialogLocalDir.equals("")) { String sel_dir = mDialogLocalDir; String n_dir = "", e_dir = ""; if (sel_dir.startsWith("/")) n_dir = sel_dir.substring(1); else n_dir = sel_dir; if (n_dir.endsWith("/")) e_dir = n_dir.substring(0, n_dir.length() - 1); else e_dir = n_dir; selectLocalDirTree(e_dir); } if (!mDialogFileName.equals("")) selectLocalDirTreeFile(mDialogFileName); } mTreeFileListView.setScrollingCacheEnabled(false); mTreeFileListView.setScrollbarFadingEnabled(false); if (mSavedViewContentsValue != null && mSavedViewContentsValue.mainDialogFilename != null) { filename.setText(mSavedViewContentsValue.mainDialogFilename); filename.setSelection(mSavedViewContentsValue.mainDialogFilenameSelStart, mSavedViewContentsValue.mainDialogFilenameTextSelEnd); dir_name.setText(mSavedViewContentsValue.mainDialogDirName); } else { // if (mDialogLocalDir.equals("")) filename.setText(mDialogLocalUuid+mDialogFileName); // else filename.setText(mDialogLocalUuid+mDialogLocalDir+"/"+mDialogFileName); // filename.setSelection(filename.getText().toString().length()); dir_name.setText(mDialogLocalDir + "/"); filename.setText(mDialogFileName); } // CommonDialog.setDlgBoxSizeLimit(mDialog,true); // setDlgBoxSize(dialog,0,0,false); if (!mDialogSingleSelect) btnOk.setEnabled(false); NotifyEvent cb_ntfy = new NotifyEvent(context); // set file list thread response listener cb_ntfy.setListener(new NotifyEventListener() { @Override public void positiveResponse(Context c, Object[] o) { int p = (Integer) o[0]; boolean p_chk = (Boolean) o[1]; if (mDialogSingleSelect) { if (mTreeFilelistAdapter.getDataItem(p).isChecked() && !p_chk) { if (p != -1) { if (mTreeFilelistAdapter.getDataItem(p).isChecked()) { if (mTreeFilelistAdapter.getDataItem(p).isDir()) { dir_name.setText(mTreeFilelistAdapter.getDataItem(p).getPath() + mTreeFilelistAdapter.getDataItem(p).getName() + "/"); // filename.setText(""); } else { dir_name.setText(mTreeFilelistAdapter.getDataItem(p).getPath()); filename.setText(mTreeFilelistAdapter.getDataItem(p).getName()); } } } } if (mDialogFileOnly) { if (filename.getText().length() > 0) { btnOk.setEnabled(true); putDlgMsg(dlg_msg, ""); } else { btnOk.setEnabled(false); putDlgMsg(dlg_msg, context.getString(R.string.msgs_file_select_edit_dlg_filename_not_specified)); } } else { if (mTreeFilelistAdapter.isDataItemIsSelected() || filename.getText().length() > 0) { btnOk.setEnabled(true); putDlgMsg(dlg_msg, ""); } else { putDlgMsg(dlg_msg, context.getString(R.string.msgs_file_select_edit_dlg_directory_not_selected)); btnOk.setEnabled(false); } } } else { if (mTreeFilelistAdapter.getDataItem(p).isDir()) { dir_name.setText(mTreeFilelistAdapter.getDataItem(p).getPath() + mTreeFilelistAdapter.getDataItem(p).getName() + "/"); } else { dir_name.setText(mTreeFilelistAdapter.getDataItem(p).getPath()); filename.setText(mTreeFilelistAdapter.getDataItem(p).getName()); } putDlgMsg(dlg_msg, ""); btnOk.setEnabled(true); } } @Override public void negativeResponse(Context c, Object[] o) { boolean checked = false; // int p=(Integer) o[0]; boolean p_chk = (Boolean) o[1]; if (mDialogSingleSelect) { if (p_chk) { for (int i = 0; i < mTreeFilelistAdapter.getDataItemCount(); i++) { if (mTreeFilelistAdapter.getDataItem(i).isChecked()) { checked = true; break; } } if (checked) btnOk.setEnabled(true); else btnOk.setEnabled(false); } } else { // Log.v("","sel="+p_chk); btnOk.setEnabled(false); for (int i = 0; i < mTreeFilelistAdapter.getDataItemCount(); i++) { if (mTreeFilelistAdapter.getDataItem(i).isChecked()) { btnOk.setEnabled(true); break; } } } } }); mTreeFilelistAdapter.setCbCheckListener(cb_ntfy); // if (mDialogLocalUuid.equals(filename.getText().toString())) btnOk.setEnabled(false); filename.addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(Editable s) { if (mDialogSingleSelect) { if (s.length() != 0) { btnOk.setEnabled(true); putDlgMsg(dlg_msg, ""); } else { btnOk.setEnabled(false); putDlgMsg(dlg_msg, context.getString(R.string.msgs_file_select_edit_dlg_filename_not_specified)); } } } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } }); NotifyEvent ntfy_expand_close = new NotifyEvent(context); ntfy_expand_close.setListener(new NotifyEventListener() { @Override public void positiveResponse(Context c, Object[] o) { int idx = (Integer) o[0]; final int pos = mTreeFilelistAdapter.getItem(idx); final TreeFilelistItem tfi = mTreeFilelistAdapter.getDataItem(pos); if (tfi.getName().startsWith("---")) return; if (tfi.isDir()) processLocalDirTree(mDialogFileOnly, mDialogLocalUuid, pos, tfi, mTreeFilelistAdapter); else { mTreeFilelistAdapter.setDataItemIsSelected(pos); dir_name.setText(mTreeFilelistAdapter.getDataItem(pos).getPath()); filename.setText(mTreeFilelistAdapter.getDataItem(pos).getName()); if (mTreeFilelistAdapter.getDataItem(pos).isDir() && mDialogFileOnly) btnOk.setEnabled(false); else btnOk.setEnabled(true); } } @Override public void negativeResponse(Context c, Object[] o) { } }); mTreeFilelistAdapter.setExpandCloseListener(ntfy_expand_close); mTreeFileListView.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> items, View view, int idx, long id) { final int pos = mTreeFilelistAdapter.getItem(idx); final TreeFilelistItem tfi = mTreeFilelistAdapter.getDataItem(pos); if (tfi.getName().startsWith("---")) return; if (tfi.isDir()) processLocalDirTree(mDialogFileOnly, mDialogLocalUuid, pos, tfi, mTreeFilelistAdapter); else { mTreeFilelistAdapter.setDataItemIsSelected(pos); dir_name.setText(mTreeFilelistAdapter.getDataItem(pos).getPath()); filename.setText(mTreeFilelistAdapter.getDataItem(pos).getName()); if (mTreeFilelistAdapter.getDataItem(pos).isDir() && mDialogFileOnly) btnOk.setEnabled(false); else btnOk.setEnabled(true); } } }); mTreeFileListView.setOnItemLongClickListener(new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> arg0, View arg1, final int position, long arg3) { return true; } }); btnHome.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { dir_name.setText("/"); } }); //Create button btnCreate.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { NotifyEvent ntfy = new NotifyEvent(context); // set file list thread response listener ntfy.setListener(new NotifyEventListener() { @Override public void positiveResponse(Context c, Object[] o) { // btnRefresh.performClick(); } @Override public void negativeResponse(Context c, Object[] o) { } }); // String mp=""; // for(TreeFilelistItem tfi:mTreeFilelistAdapter.getDataList()) { // if (tfi.isChecked()) { // mp=tfi.getPath()+tfi.getName(); // break; // } // } fileSelectEditDialogCreateBtn(activity, context, dir_name.getText().substring(0, dir_name.getText().length() - 1), "", mTreeFilelistAdapter, ntfy, mTreeFileListView); } }); //Refresh button btnRefresh.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { ArrayList<TreeFilelistItem> tfl = createLocalFilelist(mDialogFileOnly, mDialogLocalUuid, "");//mDialogLocalUuid,""); if (tfl.size() < 1) tfl.add(new TreeFilelistItem(context.getString(R.string.msgs_file_select_edit_dir_empty))); mTreeFilelistAdapter.setDataList(tfl); } }); //OK button // btnOk.setEnabled(false); btnOk.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (mDialogSingleSelect) { String[] sl_array = new String[] { dir_name.getText().toString() + filename.getText().toString() }; if (mNotifyEvent != null) mNotifyEvent.notifyToListener(true, sl_array); } else { ArrayList<String> sl = new ArrayList<String>(); ArrayList<TreeFilelistItem> tfl = mTreeFilelistAdapter.getDataList(); for (TreeFilelistItem li : tfl) { if (li.isChecked()) { if (li.isDir()) sl.add(li.getPath() + li.getName()); else sl.add(li.getPath() + li.getName()); } } String[] sl_array = new String[sl.size()]; for (int i = 0; i < sl.size(); i++) { if (mDialogSelectedFilePathWithMountPoint) sl_array[i] = sl.get(i); else sl_array[i] = sl.get(i); // Log.v("","sel="+sl_array[i]); } if (mNotifyEvent != null) mNotifyEvent.notifyToListener(true, sl_array); } // mDialog.dismiss(); mFragment.dismiss(); } }); // CANCEL? btnCancel.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // mDialog.dismiss(); mFragment.dismiss(); if (mNotifyEvent != null) mNotifyEvent.notifyToListener(false, null); } }); }
From source file:com.microsoft.windowsazure.mobileservices.MobileServiceClient.java
/** * Invokes Microsoft Azure Mobile Service authentication using a the Google * account registered in the device// w w w . ja v a2 s . co m * * @param activity The activity that triggered the authentication * @param scopes The scopes used as authentication token type for login */ public ListenableFuture<MobileServiceUser> loginWithGoogleAccount(Activity activity, String scopes) { AccountManager acMgr = AccountManager.get(activity.getApplicationContext()); Account[] accounts = acMgr.getAccountsByType(GOOGLE_ACCOUNT_TYPE); Account account; if (accounts.length == 0) { account = null; } else { account = accounts[0]; } return loginWithGoogleAccount(activity, account, scopes); }
From source file:com.yerdy.services.Yerdy.java
private boolean internalShowMessage(Activity activity, String placement, boolean first) { if (activity == null || activity.isFinishing()) return false; if (_activeMessage != null) { if (_activeMessage.isVisible() || !_activeMessage.hasReportedAction()) return false; }/*from w ww .j a va 2s . co m*/ YRDMessage msgData = getMessageForPlacement(placement); if (msgData == null) return false; YRDMessagePreseneter msg = new YRDMessagePreseneter(msgData, activity.getApplicationContext()); msg.setMessageDelegate(new PresenterDelegate()); if (first) { _messagesPresentedInRow = 1; _didDismissMessage = false; } else { _messagesPresentedInRow++; } _currentPlacement = placement; msg.show(activity); _activeMessage = msg; synchronized (_messages) { _messages.remove(msgData); } _historyTracker.addMessage(Integer.toString(msgData.id)); return true; }
From source file:com.android.launcher3.Utilities.java
public static void showEditMode(final Activity activity, final ShortcutInfo shortcutInfo) { ContextThemeWrapper theme;//from w w w . j a v a2 s.c o m final Set<String> setString = new HashSet<String>(); if (Build.VERSION.SDK_INT == Build.VERSION_CODES.M) { theme = new ContextThemeWrapper(activity, R.style.AlertDialogCustomAPI23); } else { theme = new ContextThemeWrapper(activity, R.style.AlertDialogCustom); } AlertDialog.Builder alert = new AlertDialog.Builder(theme); LinearLayout layout = new LinearLayout(activity.getApplicationContext()); layout.setOrientation(LinearLayout.VERTICAL); layout.setPadding(100, 0, 100, 100); final ImageView img = new ImageView(activity.getApplicationContext()); Drawable icon = null; if (Utilities.getAppIconPackageNamePrefEnabled(activity.getApplicationContext()) != null) { if (Utilities.getAppIconPackageNamePrefEnabled(activity.getApplicationContext()).equals("NULL")) { if (Utilities.loadBitmapPref(Launcher.getLauncherActivity(), shortcutInfo.getTargetComponent().getPackageName()) != null) { icon = new BitmapDrawable(activity.getResources(), Utilities.loadBitmapPref(activity, shortcutInfo.getTargetComponent().getPackageName())); } else { icon = new BitmapDrawable(activity.getResources(), shortcutInfo.getIcon(new IconCache(activity.getApplicationContext(), Launcher.getLauncher(activity).getDeviceProfile().inv))); } } else { if (Utilities.loadBitmapPref(Launcher.getLauncherActivity(), shortcutInfo.getTargetComponent().getPackageName()) != null) { icon = new BitmapDrawable(activity.getResources(), Utilities.loadBitmapPref(activity, shortcutInfo.getTargetComponent().getPackageName())); } else { icon = new BitmapDrawable(activity.getResources(), Launcher.getIcons().get(shortcutInfo.getTargetComponent().getPackageName())); } } } else { if (Utilities.loadBitmapPref(Launcher.getLauncherActivity(), shortcutInfo.getTargetComponent().getPackageName()) != null) { icon = new BitmapDrawable(activity.getResources(), Utilities.loadBitmapPref(activity, shortcutInfo.getTargetComponent().getPackageName())); } else { icon = new BitmapDrawable(activity.getResources(), shortcutInfo.getIcon(new IconCache(activity.getApplicationContext(), Launcher.getLauncher(Launcher.getLauncherActivity()).getDeviceProfile().inv))); } } img.setImageDrawable(icon); img.setPadding(0, 100, 0, 0); img.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { showIconPack(activity, shortcutInfo); } }); final EditText titleBox = new EditText(activity.getApplicationContext()); try { Set<String> title = new HashSet<>( Utilities.getTitle(activity, shortcutInfo.getTargetComponent().getPackageName())); for (Iterator<String> it = title.iterator(); it.hasNext();) { String titleApp = it.next(); titleBox.setText(titleApp); } } catch (Exception e) { titleBox.setText(shortcutInfo.title); } titleBox.getBackground().mutate().setColorFilter( ContextCompat.getColor(activity.getApplicationContext(), R.color.colorPrimary), PorterDuff.Mode.SRC_ATOP); layout.addView(img); layout.addView(titleBox); alert.setTitle(activity.getApplicationContext().getResources().getString(R.string.edit_label)); alert.setView(layout); alert.setPositiveButton(activity.getApplicationContext().getString(R.string.ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { for (ItemInfo itemInfo : AllAppsList.data) { if (shortcutInfo.getTargetComponent().getPackageName() .equals(itemInfo.getTargetComponent().getPackageName())) { setString.add(titleBox.getText().toString()); getPrefs(activity.getApplicationContext()).edit() .putStringSet(itemInfo.getTargetComponent().getPackageName(), setString) .apply(); Launcher.getShortcutsCreation().clearAllLayout(); applyChange(activity); } } } }); alert.setNegativeButton(activity.getApplicationContext().getString(R.string.cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { Launcher.getShortcutsCreation().clearAllLayout(); } }); alert.show(); }