List of usage examples for android.content Context toString
public String toString()
From source file:com.jins_meme.bridge.VDJMenuFragment.java
@Override public void onAttach(Context context) { Log.d("DEBUG", "VDJ:: onAttach"); super.onAttach(context); if (context instanceof OnFragmentInteractionListener) { mListener = (OnFragmentInteractionListener) context; } else {/*from ww w.j ava2 s . c om*/ throw new RuntimeException(context.toString() + " must implement OnFragmentInteractionListener"); } }
From source file:me.trashout.fragment.TrashReportOrEditFragment.java
@Override public void onAttach(Context context) { super.onAttach(context); try {//w w w . j av a2 s . c o m mCallback = (TrashListFragment.OnRefreshTrashListListener) context; } catch (ClassCastException e) { throw new ClassCastException(context.toString() + " must implement OnHeadlineSelectedListener"); } try { onTrashChangedListener = (OnTrashChangedListener) context; } catch (ClassCastException e) { throw new ClassCastException(context.toString() + " must implement OnTrashChangedListener"); } try { onDashboardChangedListener = (OnDashboardChangedListener) context; } catch (ClassCastException e) { throw new ClassCastException(context.toString() + " must implement OnDashboardChangedListener"); } }
From source file:com.vest.album.fragment.CameraBasicFragment.java
@Override public void onAttach(Context context) { super.onAttach(context); try {//from w w w. j a v a 2s . co m callback = (onPhotoCallback) context; } catch (ClassCastException e) { throw new ClassCastException(context.toString() + " must implement onResultCallback"); } }
From source file:co.tinode.tindroid.ContactsFragment.java
@Override public void onAttach(Context context) { super.onAttach(context); try {/*from w w w .j a va 2s. co m*/ // Assign callback listener which the holding activity must implement. This is used // so that when a contact item is interacted with (selected by the user) the holding // activity will be notified and can take further action such as populating the contact // detail pane (if in multi-pane layout) or starting a new activity with the contact // details (single pane layout). mOnContactSelectedListener = (OnContactsInteractionListener) context; } catch (ClassCastException e) { throw new ClassCastException(context.toString() + " must implement OnContactsInteractionListener"); } }
From source file:com.raspi.chatapp.ui.chatting.ChatFragment.java
@Override public void onAttach(Context context) { // not to be confused with onAttackClicked. This a method overridden from // the Fragment to signal that this fragment is somehow active super.onAttach(context); if (context instanceof OnChatFragmentInteractionListener) { mListener = (OnChatFragmentInteractionListener) context; } else {/*www .java 2s . c o m*/ throw new RuntimeException(context.toString() + " must implement OnChatFragmentInteractionListener"); } }
From source file:key.secretkey.SelectFolderFragment.java
@Override public void onAttach(final Context context) { super.onAttach(context); try {/*w ww .j a v a 2 s . c o m*/ mListener = new OnFragmentInteractionListener() { public void onFragmentInteraction(PasswordItem item) { if (item.getType() == PasswordItem.TYPE_CATEGORY) { // push the current password list (non filtered plz!) passListStack.push(pathStack.isEmpty() ? PasswordStorage.getPasswords(PasswordStorage.getRepositoryDirectory(context)) : PasswordStorage.getPasswords(pathStack.peek(), PasswordStorage.getRepositoryDirectory(context))); //push the category were we're going pathStack.push(item.getFile()); scrollPosition.push(recyclerView.getVerticalScrollbarPosition()); recyclerView.scrollToPosition(0); recyclerAdapter.clear(); recyclerAdapter.addAll(PasswordStorage.getPasswords(item.getFile(), PasswordStorage.getRepositoryDirectory(context))); ((AppCompatActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true); } } public void savePosition(Integer position) { } }; } catch (ClassCastException e) { throw new ClassCastException(context.toString() + " must implement OnFragmentInteractionListener"); } }
From source file:key.secretkey.PasswordFragment.java
@Override public void onAttach(final Context context) { super.onAttach(context); try {//from w w w. j ava 2s. c o m mListener = new OnFragmentInteractionListener() { public void onFragmentInteraction(PasswordItem item) { if (item.getType() == PasswordItem.TYPE_CATEGORY) { // push the current password list (non filtered plz!) passListStack.push(pathStack.isEmpty() ? PasswordStorage.getPasswords(PasswordStorage.getRepositoryDirectory(context)) : PasswordStorage.getPasswords(pathStack.peek(), PasswordStorage.getRepositoryDirectory(context))); //push the category were we're going pathStack.push(item.getFile()); scrollPosition.push(recyclerView.getVerticalScrollbarPosition()); recyclerView.scrollToPosition(0); recyclerAdapter.clear(); recyclerAdapter.addAll(PasswordStorage.getPasswords(item.getFile(), PasswordStorage.getRepositoryDirectory(context))); ((AppCompatActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true); } else { if (getArguments().getBoolean("matchWith", false)) { ((MainActivity) getActivity()).matchPasswordWithApp(item); } else { ((MainActivity) getActivity()).decryptPassword(item); } } } public void savePosition(Integer position) { } }; } catch (ClassCastException e) { throw new ClassCastException(context.toString() + " must implement OnFragmentInteractionListener"); } }
From source file:ax.ha.it.smsalarm.handler.SharedPreferencesHandler.java
/** * To store values to {@link SharedPreferences}. It set's different values of different instances depending on input parameters.<br> * Example usage://from w w w.ja v a2s . c o m * <p> * <code>storePrefs(PrefKey.SHARED_PREF, PrefKey.ACKNUMBER_KEY, "0457 0000 000", context)</code> * * @param sharedPreference * <code>Shared Preferences</code> to which given object is stored to. * @param sharedPreferencesKey * <code>Key</code> to which <code>Shared Preference</code> the object is going to be stored to. * @param object * Object to be stored to <code>Shared Preference</code>, supported instances are <code>Integer</code>, <code>String</code>, * <code>Boolean</code> and <code>List(containing instances of String)</code>. * @param context * Context in which <code>Shared Preferences</code> handling is done. * @see #fetchPrefs(PrefKey, PrefKey, DataType, Context) * @see #fetchPrefs(PrefKey, PrefKey, DataType, Context, Object) */ @SuppressWarnings("unchecked") public void storePrefs(PrefKey sharedPreference, PrefKey sharedPreferencesKey, Object object, Context context) { // Set shared preferences from context and set listener to it sharedPref = context.getSharedPreferences(sharedPreference.getKey(), Context.MODE_PRIVATE); sharedPref.registerOnSharedPreferenceChangeListener(listener); // Resolve editor for the shared preferences prefsEditor = sharedPref.edit(); if (object instanceof Integer) { // Put shared preferences as Integer prefsEditor.putInt(sharedPreferencesKey.getKey(), (Integer) object); prefsEditor.commit(); } else if (object instanceof String) { // Put shared preferences as String prefsEditor.putString(sharedPreferencesKey.getKey(), (String) object); prefsEditor.commit(); } else if (object instanceof Boolean) { // Put shared preferences as Boolean prefsEditor.putBoolean(sharedPreferencesKey.getKey(), (Boolean) object); prefsEditor.commit(); } else if (object instanceof List<?>) { // Create a new list and store object to it List<String> list = new ArrayList<String>(); list = (List<String>) object; // Use JSON to serialize ArrayList containing strings JSONArray a = new JSONArray(); // Iterate through each element in list and add object in JSON object for (int i = 0; i < list.size(); i++) { a.put(list.get(i)); } // If list is not empty add it to shared preferences, if empty add empty string to preferences if (!list.isEmpty()) { prefsEditor.putString(sharedPreferencesKey.getKey(), a.toString()); prefsEditor.commit(); } else { prefsEditor.putString(sharedPreferencesKey.getKey(), ""); prefsEditor.commit(); } } else { // Unregister listener when shit hits the fan also sharedPref.unregisterOnSharedPreferenceChangeListener(listener); // If application end up here then some error has occurred IllegalArgumentException exception = new IllegalArgumentException( "Failed to store object to shared preferences: \"" + sharedPreference.getKey() + "\", with key: \"" + sharedPreferencesKey.getKey() + "\" and context: \"" + context.toString() + "\". Cause: \"Object of unsupported instance was given as argument\", given object is instance of: \"" + object.getClass().getSimpleName() + "\", valid instances are: \"int\", \"String\", \"boolean\" and \"List<String>\""); Log.e(LOG_TAG + ":storePrefs()", "An exception occurred while setting shared preferences", exception); throw exception; } // Remember to unregister the listener sharedPref.unregisterOnSharedPreferenceChangeListener(listener); }
From source file:ax.ha.it.smsalarm.handler.SharedPreferencesHandler.java
/** * To fetch values in {@link SharedPreferences}. It fetches different values depending on input parameters. This method also takes a default value * to be fetched from <code>Shared Preferences</code> if no value exist. <br> * Returns fetched value if all is fine else an {@link IllegalArgumentException} is thrown. * <p>//from www . j a va 2s . com * Example usage:<br> * <code>String s = fetchPrefs(PrefKey.SHARED_PREF, PrefKey.ACK_NUMBER_KEY, * DataType.STRING, context, "empty")</code>, this will retrieve a <code>String</code> from key <code>ACK_NUMBER_KEY</code> within given * <code>context</code>. * <p> * <b><i>NOTE. The default value does only work for data types INTEGER, STRING and BOOLEAN. A default value for data type LIST will not be taken * in consideration</i></b>. <br> * * @param sharedPreferences * <code>Shared Preferences</code> from which the values are fetched from. * @param sharedPreferencesKey * <code>Key</code> in which <code>Shared Preferences</code> is stored. * @param type * Which type of data that's supposed to be fetched. * @param context * Context in which <code>Shared Preferences</code> handling is done. * @param defaultObject * Default value to be fetched from <code>Shared Preferences</code> if no previous value exist. * @return Returns an object with the fetched value. This object can be an instance of <b><i>Integer</i></b>, <b><i>String</i></b>, * <b><i>Boolean</i></b> or a <b><i>List of Strings</i></b>. * @see #fetchPrefs(PrefKey, PrefKey, DataType, Context) * @see #storePrefs(PrefKey, PrefKey, Object, Context) */ public Object fetchPrefs(PrefKey sharedPreferences, PrefKey sharedPreferencesKey, DataType type, Context context, Object defaultObject) { // Set shared preferences from context sharedPref = context.getSharedPreferences(sharedPreferences.getKey(), Context.MODE_PRIVATE); switch (type) { case INTEGER: // Check that defaultObject is of correct instance else collect "hard coded" default value of 0 if (defaultObject instanceof Integer) { return sharedPref.getInt(sharedPreferencesKey.getKey(), (Integer) defaultObject); } else { return sharedPref.getInt(sharedPreferencesKey.getKey(), 0); } case STRING: // Check that defaultObject is of correct instance else collect "hard coded" default value of "" if (defaultObject instanceof String) { return sharedPref.getString(sharedPreferencesKey.getKey(), (String) defaultObject); } else { return sharedPref.getString(sharedPreferencesKey.getKey(), ""); } case BOOLEAN: // Check that defaultObject is of correct instance else collect "hard coded" default value of false if (defaultObject instanceof Boolean) { return sharedPref.getBoolean(sharedPreferencesKey.getKey(), (Boolean) defaultObject); } else { return sharedPref.getBoolean(sharedPreferencesKey.getKey(), false); } case LIST: // Retrieve JSON string String json = sharedPref.getString(sharedPreferencesKey.getKey(), ""); // List of Strings containing List<String> list = new ArrayList<String>(); // If JSON string is not empty if (json != "") { try { // Create a JSONArray from JSON string and retrieve strings from it and and them to a List<String> JSONArray a = new JSONArray(json); for (int i = 0; i < a.length(); i++) { String secondaryListenNumber = a.optString(i); list.add(secondaryListenNumber); } return list; } catch (JSONException e) { Log.e(LOG_TAG + ":fetchPrefs()", "Failed to retrieve List<String> from shared preferences: \"" + sharedPreferences.getKey() + "\", with key: \"" + sharedPreferencesKey.getKey() + "\", type: \"" + type.name() + "\" and context: \"" + context.toString() + "\"", e); } } else { // <--If JSON string is empty, return empty List return list; } break; default: // DO NOTHING, EXCEPTION WILL BE THROWN LATER! } // If application end up here then some error has occurred IllegalArgumentException exception = new IllegalArgumentException("Failed to fetch shared preferences: \"" + sharedPreferences.getKey() + "\", with key: \"" + sharedPreferencesKey.getKey() + "\", data type: \"" + type.name() + "\" and context: \"" + context.toString() + "\". Cause: \"Data type given as argument is unsupported\", valid data types are: \"INTEGER\", \"STRING\", \"BOOLEAN\" and \"LIST\""); Log.e(LOG_TAG + ":fetchPrefs()", "An exception occurred while fetching shared preferences", exception); throw exception; }