Example usage for android.app Activity getApplication

List of usage examples for android.app Activity getApplication

Introduction

In this page you can find the example usage for android.app Activity getApplication.

Prototype

public final Application getApplication() 

Source Link

Document

Return the application that owns this activity.

Usage

From source file:com.kncwallet.wallet.ui.SendCoinsFragment.java

@Override
public void onAttach(final Activity activity) {
    super.onAttach(activity);

    this.activity = (AbstractBindServiceActivity) activity;
    this.application = (WalletApplication) activity.getApplication();
    this.prefs = PreferenceManager.getDefaultSharedPreferences(activity);
    this.wallet = application.getWallet();
    this.contentResolver = activity.getContentResolver();
    this.loaderManager = getLoaderManager();

}

From source file:com.readystatesoftware.ghostlog.ServerlessLogScreen.java

public ServerlessLogScreen(Activity activity) {
    mContext = activity;//from w  w w .  j  a va 2s .  co m
    mPrefs = PreferenceManager.getDefaultSharedPreferences(mContext);
    mPrefs.registerOnSharedPreferenceChangeListener(this);
    mLogLevel = mPrefs.getString(getString(R.string.pref_log_level), LogLine.LEVEL_VERBOSE);
    mAutoFilter = mPrefs.getBoolean(getString(R.string.pref_auto_filter), false);
    mTagFilter = mPrefs.getString(getString(R.string.pref_tag_filter), null);

    mLogListView = (ListView) LayoutInflater.from(mContext).inflate(R.layout.window_log, null);

    mContext.getApplication().registerActivityLifecycleCallbacks(new Application.ActivityLifecycleCallbacks() {
        @Override
        public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
        }

        @Override
        public void onActivityStopped(Activity activity) {
        }

        @Override
        public void onActivityStarted(Activity activity) {
        }

        @Override
        public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
        }

        @Override
        public void onActivityResumed(Activity activity) {
            System.out.println("onActivityResumed:" + activity);
            if (sWasRunning) {
                start();
                sWasRunning = false;
            }
        }

        @Override
        public void onActivityPaused(Activity activity) {
            System.out.println("onActivityPaused:" + activity);
            if (sIsRunning) {
                stop(activity);
                sWasRunning = true;
            }
        }

        @Override
        public void onActivityDestroyed(Activity activity) {
            activity.getApplication().unregisterActivityLifecycleCallbacks(this);
        }
    });
}

From source file:com.microsoft.onedrive.apiexplorer.ItemFragment.java

/**
 * Renames a sourceItem//from w  w  w.  ja v  a 2  s  .  c om
 * @param sourceItem The sourceItem to rename
 */
private void renameItem(final Item sourceItem) {
    final Activity activity = getActivity();
    final EditText newName = new EditText(activity);
    newName.setInputType(InputType.TYPE_CLASS_TEXT);
    newName.setHint(sourceItem.name);
    final AlertDialog alertDialog = new AlertDialog.Builder(activity).setTitle(R.string.rename)
            .setIcon(android.R.drawable.ic_menu_edit).setView(newName)
            .setPositiveButton(R.string.rename, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(final DialogInterface dialog, final int which) {
                    final ICallback<Item> callback = new DefaultCallback<Item>(getActivity()) {
                        @Override
                        public void success(final Item item) {
                            Toast.makeText(activity,
                                    activity.getString(R.string.renamed_item, sourceItem.name, item.name),
                                    Toast.LENGTH_LONG).show();
                            refresh();
                            dialog.dismiss();
                        }

                        @Override
                        public void failure(final ClientException error) {
                            Toast.makeText(activity, activity.getString(R.string.rename_error, sourceItem.name),
                                    Toast.LENGTH_LONG).show();
                            dialog.dismiss();
                        }
                    };
                    Item updatedItem = new Item();
                    updatedItem.id = sourceItem.id;
                    updatedItem.name = newName.getText().toString();
                    ((BaseApplication) activity.getApplication()).getOneDriveClient().getDrive()
                            .getItems(updatedItem.id).buildRequest().update(updatedItem, callback);
                }
            }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(final DialogInterface dialog, final int which) {
                    dialog.cancel();
                }
            }).create();
    alertDialog.show();
}

From source file:com.microsoft.onedrive.apiexplorer.ItemFragment.java

/**
 * Creates a folder//from w w  w.j a  va  2  s  .  c  o  m
 * @param item The parent of the folder to create
 */
private void createFolder(final Item item) {
    final Activity activity = getActivity();
    final EditText newName = new EditText(activity);
    newName.setInputType(InputType.TYPE_CLASS_TEXT);
    newName.setHint(activity.getString(R.string.new_folder_hint));

    final AlertDialog alertDialog = new AlertDialog.Builder(activity).setTitle(R.string.create_folder)
            .setView(newName).setIcon(android.R.drawable.ic_menu_add)
            .setPositiveButton(R.string.create_folder, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(final DialogInterface dialog, final int which) {
                    final ICallback<Item> callback = new DefaultCallback<Item>(activity) {
                        @Override
                        public void success(final Item createdItem) {
                            Toast.makeText(activity,
                                    activity.getString(R.string.created_folder, createdItem.name, item.name),
                                    Toast.LENGTH_LONG).show();
                            refresh();
                            dialog.dismiss();
                        }

                        @Override
                        public void failure(final ClientException error) {
                            super.failure(error);
                            Toast.makeText(activity, activity.getString(R.string.new_folder_error, item.name),
                                    Toast.LENGTH_LONG).show();
                            dialog.dismiss();
                        }
                    };

                    final Item newItem = new Item();
                    newItem.name = newName.getText().toString();
                    newItem.folder = new Folder();

                    ((BaseApplication) activity.getApplication()).getOneDriveClient().getDrive()
                            .getItems(mItemId).getChildren().buildRequest().create(newItem, callback);
                }
            }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(final DialogInterface dialog, final int which) {
                    dialog.cancel();
                }
            }).create();
    alertDialog.show();
}