List of usage examples for android.app Activity getApplicationContext
@Override
public Context getApplicationContext()
From source file:io.teak.sdk.Teak.java
private static void cleanup(Activity activity) { if (Teak.appStore != null) { Teak.appStore.dispose();/*from w w w . jav a2 s .c om*/ } RemoteConfiguration.removeEventListener(Teak.remoteConfigurationEventListener); Session.removeEventListener(Teak.sessionEventListener); if (Teak.facebookAccessTokenBroadcast != null) { Teak.facebookAccessTokenBroadcast.unregister(activity.getApplicationContext()); } activity.getApplication().unregisterActivityLifecycleCallbacks(Teak.lifecycleCallbacks); }
From source file:com.olheingenieros.listexample.ui.TutorialViewBinder.java
@Override public boolean setViewValue(final View view, final Cursor cursor, final int index) { if (index == cursor.getColumnIndex(TutListDatabase.COL_DATE)) { // Get a locale based string for the date final Activity a = new TutListActivity(); final Context context = a.getApplicationContext(); final DateFormat formatter = android.text.format.DateFormat.getDateFormat(context); final long date = cursor.getLong(index); final Date dateObj = new Date(date * 1000); ((TextView) view).setText(formatter.format(dateObj)); return true; }/*from w w w . j av a 2 s .co m*/ return false; }
From source file:za.co.paulscott.antifitness.ModuleFragment.java
@Override public void onAttach(Activity activity) { super.onAttach(activity); activity.getApplicationContext().bindService(new Intent(activity, MetaWearBLEService.class), this, Context.BIND_AUTO_CREATE); }
From source file:org.musicbrainz.mobile.dialog.ConnectionErrorDialog.java
@Override public void onAttach(Activity activity) { super.onAttach(activity); context = activity.getApplicationContext(); try {/*from www .j a va 2 s. c om*/ callbacks = (ConnectionErrorCallbacks) activity; } catch (ClassCastException e) { throw new ClassCastException( activity.toString() + " must implement " + ConnectionErrorCallbacks.class.getSimpleName()); } }
From source file:com.buddi.client.ModuleFragment.java
@Override public void onAttach(Activity activity) { super.onAttach(activity); activity.getApplicationContext().bindService(new Intent(activity, BuddiBLEService.class), this, Context.BIND_AUTO_CREATE); }
From source file:gtikhono.msse.asu.edu.moviedescriptions.MovieLibrary.java
public void loadMovies(Activity main) { try {/*from w ww .j a va2s . c o m*/ InputStream jsonMoviesStream = main.getApplicationContext().getResources() .openRawResource(R.raw.movies); BufferedReader reader = new BufferedReader(new InputStreamReader(jsonMoviesStream)); JSONObject jsonMoviesObject = new JSONObject(new JSONTokener(reader.readLine())); Iterator<String> iterator = jsonMoviesObject.keys(); while (iterator.hasNext()) { String titleKey = iterator.next(); JSONObject movie = jsonMoviesObject.optJSONObject(titleKey); if (movie != null) { MovieDescription moviedescription = new MovieDescription(movie.toString()); movieHashmap.put(titleKey, moviedescription); System.out.println(moviedescription); } } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.adithya321.sharesanalysis.database.RealmBackupRestore.java
public RealmBackupRestore(Activity activity) { this.realm = new DatabaseHandler(activity.getApplicationContext()).getRealmInstance(); this.activity = activity; }
From source file:org.catrobat.catroid.utils.UtilMerge.java
private static void showBackgroundNotEmptyDialog(Project projectToMergeFrom, final Activity activity) { final Project copyProjectToMergeFrom = projectToMergeFrom; final Activity copyActivity = activity; DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() { @Override/*from w ww . j a v a 2s .com*/ public void onClick(DialogInterface dialog, int which) { switch (which) { case DialogInterface.BUTTON_POSITIVE: try { Project mergedProject = appendProjects(project, copyProjectToMergeFrom, copyActivity); ProjectManager.getInstance().setProject(mergedProject); ProjectManager.getInstance().saveProject(activity.getApplicationContext()); } catch (IOException e) { ToastUtil.showError(copyActivity, R.string.error_merge); Log.e(TAG, "IOException " + e.getMessage()); } break; } } }; String question = activity.getString(R.string.error_bricks_in_background); AlertDialog.Builder builder = new CustomAlertDialogBuilder(activity); builder.setTitle(R.string.warning); builder.setMessage(question); builder.setPositiveButton(activity.getString(R.string.main_menu_continue), dialogClickListener); builder.setNegativeButton(activity.getString(R.string.abort), dialogClickListener); Dialog errorDialog = builder.create(); errorDialog.show(); }
From source file:io.teak.sdk.Teak.java
/** * Initialize Teak and tell it to listen to the lifecycle events of {@link Activity}. * <p/>//w w w. j a va2s. c om * <p>Call this function from the {@link Activity#onCreate} function of your <code>Activity</code> * <b>before</b> the call to <code>super.onCreate()</code></p> * * @param activity The main <code>Activity</code> of your app. */ public static void onCreate(Activity activity) { Log.d(LOG_TAG, "Android SDK Version: " + Teak.SDKVersion); if (activity == null) { Log.e(LOG_TAG, "null Activity passed to onCreate, Teak is disabled."); Teak.setState(State.Disabled); return; } { String airSdkVersion = Helpers.getStringResourceByName("io_teak_air_sdk_version", activity.getApplicationContext()); if (airSdkVersion != null) { Log.d(LOG_TAG, "Adobe AIR SDK Version: " + airSdkVersion); } } // Set up debug logging ASAP try { final Context context = activity.getApplicationContext(); final ApplicationInfo applicationInfo = context.getApplicationInfo(); Teak.debugConfiguration = new DebugConfiguration(context); Teak.isDebug = Teak.forceDebug || Teak.debugConfiguration.forceDebug || (applicationInfo != null && (0 != (applicationInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE))); } catch (Exception e) { Log.e(LOG_TAG, "Error creating DebugConfiguration. " + Log.getStackTraceString(e)); } if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) { Log.e(LOG_TAG, "Teak requires API level 14 to operate. Teak is disabled."); Teak.setState(State.Disabled); } else { try { Application application = activity.getApplication(); synchronized (Teak.stateMutex) { if (Teak.state == State.Allocated) { application.registerActivityLifecycleCallbacks(Teak.lifecycleCallbacks); } } } catch (Exception e) { Log.e(LOG_TAG, "Failed to register Activity lifecycle callbacks. Teak is disabled. " + Log.getStackTraceString(e)); Teak.setState(State.Disabled); } } }
From source file:im.vector.util.BugReporter.java
/** * Send a bug report either with email or with Vector. *///www . jav a2 s.c o m public static void sendBugReport() { final Activity currentActivity = VectorApp.getCurrentActivity(); // no current activity so cannot display an alert if (null == currentActivity) { sendBugReport(VectorApp.getInstance().getApplicationContext(), true, true, "", null); return; } final Context appContext = currentActivity.getApplicationContext(); LayoutInflater inflater = currentActivity.getLayoutInflater(); View dialogLayout = inflater.inflate(R.layout.dialog_bug_report, null); final AlertDialog.Builder dialog = new AlertDialog.Builder(currentActivity); dialog.setTitle(R.string.send_bug_report); dialog.setView(dialogLayout); final EditText bugReportText = (EditText) dialogLayout.findViewById(R.id.bug_report_edit_text); final CheckBox includeLogsButton = (CheckBox) dialogLayout .findViewById(R.id.bug_report_button_include_logs); final CheckBox includeCrashLogsButton = (CheckBox) dialogLayout .findViewById(R.id.bug_report_button_include_crash_logs); final ProgressBar progressBar = (ProgressBar) dialogLayout.findViewById(R.id.bug_report_progress_view); final TextView progressTextView = (TextView) dialogLayout.findViewById(R.id.bug_report_progress_text_view); dialog.setPositiveButton(R.string.send, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // will be overridden to avoid dismissing the dialog while displaying the progress } }); dialog.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // will be overridden to avoid dismissing the dialog while displaying the progress } }); // final AlertDialog bugReportDialog = dialog.show(); final Button cancelButton = bugReportDialog.getButton(AlertDialog.BUTTON_NEGATIVE); final Button sendButton = bugReportDialog.getButton(AlertDialog.BUTTON_POSITIVE); if (null != cancelButton) { cancelButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // check if there is no upload in progress if (includeLogsButton.isEnabled()) { bugReportDialog.dismiss(); } else { mIsCancelled = true; cancelButton.setEnabled(false); } } }); } if (null != sendButton) { sendButton.setEnabled(false); sendButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // disable the active area while uploading the bug report bugReportText.setEnabled(false); sendButton.setEnabled(false); includeLogsButton.setEnabled(false); includeCrashLogsButton.setEnabled(false); progressTextView.setVisibility(View.VISIBLE); progressTextView.setText(appContext.getString(R.string.send_bug_report_progress, 0 + "")); progressBar.setVisibility(View.VISIBLE); progressBar.setProgress(0); sendBugReport(VectorApp.getInstance(), includeLogsButton.isChecked(), includeCrashLogsButton.isChecked(), bugReportText.getText().toString(), new IMXBugReportListener() { @Override public void onUploadFailed(String reason) { try { if (null != VectorApp.getInstance() && !TextUtils.isEmpty(reason)) { Toast.makeText(VectorApp.getInstance(), VectorApp.getInstance() .getString(R.string.send_bug_report_failed, reason), Toast.LENGTH_LONG).show(); } } catch (Exception e) { Log.e(LOG_TAG, "## onUploadFailed() : failed to display the toast " + e.getMessage()); } try { // restore the dialog if the upload failed bugReportText.setEnabled(true); sendButton.setEnabled(true); includeLogsButton.setEnabled(true); includeCrashLogsButton.setEnabled(true); cancelButton.setEnabled(true); progressTextView.setVisibility(View.GONE); progressBar.setVisibility(View.GONE); } catch (Exception e) { Log.e(LOG_TAG, "## onUploadFailed() : failed to restore the dialog button " + e.getMessage()); try { bugReportDialog.dismiss(); } catch (Exception e2) { Log.e(LOG_TAG, "## onUploadFailed() : failed to dismiss the dialog " + e2.getMessage()); } } mIsCancelled = false; } @Override public void onUploadCancelled() { onUploadFailed(null); } @Override public void onProgress(int progress) { if (progress > 100) { Log.e(LOG_TAG, "## onProgress() : progress > 100"); progress = 100; } else if (progress < 0) { Log.e(LOG_TAG, "## onProgress() : progress < 0"); progress = 0; } progressBar.setProgress(progress); progressTextView.setText( appContext.getString(R.string.send_bug_report_progress, progress + "")); } @Override public void onUploadSucceed() { try { if (null != VectorApp.getInstance()) { Toast.makeText(VectorApp.getInstance(), VectorApp.getInstance().getString( R.string.send_bug_report_sent), Toast.LENGTH_LONG).show(); } } catch (Exception e) { Log.e(LOG_TAG, "## onUploadSucceed() : failed to dismiss the toast " + e.getMessage()); } try { bugReportDialog.dismiss(); } catch (Exception e) { Log.e(LOG_TAG, "## onUploadSucceed() : failed to dismiss the dialog " + e.getMessage()); } } }); } }); } bugReportText.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { if (null != sendButton) { sendButton.setEnabled(bugReportText.getText().toString().length() > 10); } } @Override public void afterTextChanged(Editable s) { } }); }