Example usage for android.content.res Resources getString

List of usage examples for android.content.res Resources getString

Introduction

In this page you can find the example usage for android.content.res Resources getString.

Prototype

@NonNull
public String getString(@StringRes int id) throws NotFoundException 

Source Link

Document

Return the string value associated with a particular resource ID.

Usage

From source file:com.hichinaschool.flashcards.anki.CardBrowser.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    Themes.applyTheme(this);
    super.onCreate(savedInstanceState);

    View mainView = getLayoutInflater().inflate(R.layout.card_browser, null);
    setContentView(mainView);/*w  w w  .  j a  va  2 s.co m*/
    Themes.setContentStyle(mainView, Themes.CALLER_CARDBROWSER);

    mCol = AnkiDroidApp.getCol();
    if (mCol == null) {
        reloadCollection(savedInstanceState);
        return;
    }
    mDeckNames = new HashMap<String, String>();
    for (long did : mCol.getDecks().allIds()) {
        mDeckNames.put(String.valueOf(did), mCol.getDecks().name(did));
    }
    registerExternalStorageListener();

    Intent i = getIntent();
    mWholeCollection = i.hasExtra("fromDeckpicker") && i.getBooleanExtra("fromDeckpicker", false);

    mBackground = Themes.getCardBrowserBackground();

    SharedPreferences preferences = AnkiDroidApp.getSharedPrefs(getBaseContext());
    int sflRelativeFontSize = preferences.getInt("relativeCardBrowserFontSize", DEFAULT_FONT_SIZE_RATIO);
    String sflCustomFont = preferences.getString("browserEditorFont", "");
    mPrefFixArabic = preferences.getBoolean("fixArabicText", false);

    Resources res = getResources();
    mOrderByFields = res.getStringArray(R.array.card_browser_order_labels);
    try {
        mOrder = CARD_ORDER_NONE;
        String colOrder = mCol.getConf().getString("sortType");
        for (int c = 0; c < fSortTypes.length; ++c) {
            if (fSortTypes[c].equals(colOrder)) {
                mOrder = c;
                break;
            }
        }
        if (mOrder == 1 && preferences.getBoolean("cardBrowserNoSorting", false)) {
            mOrder = 0;
        }
        mOrderAsc = Upgrade.upgradeJSONIfNecessary(mCol, mCol.getConf(), "sortBackwards", false);
        // default to descending for non-text fields
        if (fSortTypes[mOrder].equals("noteFld")) {
            mOrderAsc = !mOrderAsc;
        }
    } catch (JSONException e) {
        throw new RuntimeException(e);
    }

    mCards = new ArrayList<HashMap<String, String>>();
    mCardsListView = (ListView) findViewById(R.id.card_browser_list);

    mCardsAdapter = new SizeControlledListAdapter(this, mCards, R.layout.card_item,
            new String[] { "sfld", "deck", "flags" },
            new int[] { R.id.card_sfld, R.id.card_deck, R.id.card_item }, sflRelativeFontSize, sflCustomFont);
    mCardsAdapter.setViewBinder(new SimpleAdapter.ViewBinder() {
        @Override
        public boolean setViewValue(View view, Object arg1, String text) {
            if (view.getId() == R.id.card_item) {
                int which = BACKGROUND_NORMAL;
                if (text.equals("1")) {
                    which = BACKGROUND_SUSPENDED;
                } else if (text.equals("2")) {
                    which = BACKGROUND_MARKED;
                } else if (text.equals("3")) {
                    which = BACKGROUND_MARKED_SUSPENDED;
                }
                view.setBackgroundResource(mBackground[which]);
                return true;
            } else if (view.getId() == R.id.card_deck && text.length() > 0) {
                view.setVisibility(View.VISIBLE);
            }
            return false;
        }
    });

    mCardsListView.setAdapter(mCardsAdapter);
    mCardsListView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            mPositionInCardsList = position;
            long cardId = Long.parseLong(mCards.get(mPositionInCardsList).get("id"));
            sCardBrowserCard = mCol.getCard(cardId);
            Intent editCard = new Intent(CardBrowser.this, CardEditor.class);
            editCard.putExtra(CardEditor.EXTRA_CALLER, CardEditor.CALLER_CARDBROWSER_EDIT);
            editCard.putExtra(CardEditor.EXTRA_CARD_ID, sCardBrowserCard.getId());
            startActivityForResult(editCard, EDIT_CARD);
            if (AnkiDroidApp.SDK_VERSION > 4) {
                ActivityTransitionAnimation.slide(CardBrowser.this, ActivityTransitionAnimation.LEFT);
            }
        }
    });
    registerForContextMenu(mCardsListView);

    mSearchEditText = (EditText) findViewById(R.id.card_browser_search);
    mSearchEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView view, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                onSearch();
                return true;
            }
            return false;
        }
    });
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    mSearchButton = (ImageButton) findViewById(R.id.card_browser_search_button);
    mSearchButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onSearch();
        }
    });

    mSearchTerms = "";
    if (mWholeCollection) {
        mRestrictOnDeck = "";
        setTitle(res.getString(R.string.card_browser_all_decks));
    } else {
        try {
            String deckName = mCol.getDecks().current().getString("name");
            mRestrictOnDeck = "deck:'" + deckName + "' ";
            setTitle(deckName);
        } catch (JSONException e) {
            throw new RuntimeException(e);
        }
    }

    mSelectedTags = new HashSet<String>();

    if (!preferences.getBoolean("cardBrowserNoSearchOnOpen", false)) {
        searchCards();
    }
}

From source file:be.ppareit.swiftp.gui.PreferenceFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.preferences);

    final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity());
    Resources resources = getResources();

    TwoStatePreference runningPref = findPref("running_switch");
    updateRunningState();//  w  w  w . ja  va2  s . co  m
    runningPref.setOnPreferenceChangeListener((preference, newValue) -> {
        if ((Boolean) newValue) {
            startServer();
        } else {
            stopServer();
        }
        return true;
    });

    PreferenceScreen prefScreen = findPref("preference_screen");
    Preference marketVersionPref = findPref("market_version");
    marketVersionPref.setOnPreferenceClickListener(preference -> {
        // start the market at our application
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setData(Uri.parse("market://details?id=be.ppareit.swiftp"));
        try {
            // this can fail if there is no market installed
            startActivity(intent);
        } catch (Exception e) {
            Cat.e("Failed to launch the market.");
            e.printStackTrace();
        }
        return false;
    });
    if (!App.isFreeVersion()) {
        prefScreen.removePreference(marketVersionPref);
    }

    updateLoginInfo();

    EditTextPreference usernamePref = findPref("username");
    usernamePref.setOnPreferenceChangeListener((preference, newValue) -> {
        String newUsername = (String) newValue;
        if (preference.getSummary().equals(newUsername))
            return false;
        if (!newUsername.matches("[a-zA-Z0-9]+")) {
            Toast.makeText(getActivity(), R.string.username_validation_error, Toast.LENGTH_LONG).show();
            return false;
        }
        stopServer();
        return true;
    });

    mPassWordPref = findPref("password");
    mPassWordPref.setOnPreferenceChangeListener((preference, newValue) -> {
        stopServer();
        return true;
    });
    mAutoconnectListPref = findPref("autoconnect_preference");
    mAutoconnectListPref.setOnPopulateListener(pref -> {
        Cat.d("autoconnect populate listener");

        WifiManager wifiManager = (WifiManager) getActivity().getApplicationContext()
                .getSystemService(Context.WIFI_SERVICE);
        List<WifiConfiguration> configs = wifiManager.getConfiguredNetworks();
        if (configs == null) {
            Cat.e("Unable to receive wifi configurations, bark at user and bail");
            Toast.makeText(getActivity(), R.string.autoconnect_error_enable_wifi_for_access_points,
                    Toast.LENGTH_LONG).show();
            return;
        }
        CharSequence[] ssids = new CharSequence[configs.size()];
        CharSequence[] niceSsids = new CharSequence[configs.size()];
        for (int i = 0; i < configs.size(); ++i) {
            ssids[i] = configs.get(i).SSID;
            String ssid = configs.get(i).SSID;
            if (ssid.length() > 2 && ssid.startsWith("\"") && ssid.endsWith("\"")) {
                ssid = ssid.substring(1, ssid.length() - 1);
            }
            niceSsids[i] = ssid;
        }
        pref.setEntries(niceSsids);
        pref.setEntryValues(ssids);
    });
    mAutoconnectListPref.setOnPreferenceClickListener(preference -> {
        Cat.d("Clicked");
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            if (ActivityCompat.checkSelfPermission(getContext(),
                    Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_DENIED) {
                if (ActivityCompat.shouldShowRequestPermissionRationale(getActivity(),
                        Manifest.permission.ACCESS_COARSE_LOCATION)) {
                    new AlertDialog.Builder(getContext()).setTitle(R.string.request_coarse_location_dlg_title)
                            .setMessage(R.string.request_coarse_location_dlg_message)
                            .setPositiveButton(android.R.string.ok, (dialog, which) -> {
                                requestPermissions(new String[] { Manifest.permission.ACCESS_COARSE_LOCATION },
                                        ACCESS_COARSE_LOCATION_REQUEST_CODE);
                            }).setOnCancelListener(dialog -> {
                                mAutoconnectListPref.getDialog().cancel();
                            }).create().show();
                } else {
                    requestPermissions(new String[] { Manifest.permission.ACCESS_COARSE_LOCATION },
                            ACCESS_COARSE_LOCATION_REQUEST_CODE);
                }
            }
        }
        return false;
    });

    EditTextPreference portnum_pref = findPref("portNum");
    portnum_pref.setSummary(sp.getString("portNum", resources.getString(R.string.portnumber_default)));
    portnum_pref.setOnPreferenceChangeListener((preference, newValue) -> {
        String newPortnumString = (String) newValue;
        if (preference.getSummary().equals(newPortnumString))
            return false;
        int portnum = 0;
        try {
            portnum = Integer.parseInt(newPortnumString);
        } catch (Exception e) {
            Cat.d("Error parsing port number! Moving on...");
        }
        if (portnum <= 0 || 65535 < portnum) {
            Toast.makeText(getActivity(), R.string.port_validation_error, Toast.LENGTH_LONG).show();
            return false;
        }
        preference.setSummary(newPortnumString);
        stopServer();
        return true;
    });

    Preference chroot_pref = findPref("chrootDir");
    chroot_pref.setSummary(FsSettings.getChrootDirAsString());
    chroot_pref.setOnPreferenceClickListener(preference -> {
        AlertDialog folderPicker = new FolderPickerDialogBuilder(getActivity(), FsSettings.getChrootDir())
                .setSelectedButton(R.string.select, path -> {
                    if (preference.getSummary().equals(path))
                        return;
                    if (!FsSettings.setChrootDir(path))
                        return;
                    // TODO: this is a hotfix, create correct resources, improve UI/UX
                    final File root = new File(path);
                    if (!root.canRead()) {
                        Toast.makeText(getActivity(), "Notice that we can't read/write in this folder.",
                                Toast.LENGTH_LONG).show();
                    } else if (!root.canWrite()) {
                        Toast.makeText(getActivity(),
                                "Notice that we can't write in this folder, reading will work. Writing in sub folders might work.",
                                Toast.LENGTH_LONG).show();
                    }

                    preference.setSummary(path);
                    stopServer();
                }).setNegativeButton(R.string.cancel, null).create();
        folderPicker.show();
        return true;
    });

    final CheckBoxPreference wakelock_pref = findPref("stayAwake");
    wakelock_pref.setOnPreferenceChangeListener((preference, newValue) -> {
        stopServer();
        return true;
    });

    final CheckBoxPreference writeExternalStorage_pref = findPref("writeExternalStorage");
    String externalStorageUri = FsSettings.getExternalStorageUri();
    if (externalStorageUri == null) {
        writeExternalStorage_pref.setChecked(false);
    }
    writeExternalStorage_pref.setOnPreferenceChangeListener((preference, newValue) -> {
        if ((boolean) newValue) {
            Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
            startActivityForResult(intent, ACTION_OPEN_DOCUMENT_TREE);
            return false;
        } else {
            FsSettings.setExternalStorageUri(null);
            return true;
        }
    });

    ListPreference theme = findPref("theme");
    theme.setSummary(theme.getEntry());
    theme.setOnPreferenceChangeListener((preference, newValue) -> {
        theme.setSummary(theme.getEntry());
        getActivity().recreate();
        return true;
    });

    Preference help = findPref("help");
    help.setOnPreferenceClickListener(preference -> {
        Cat.v("On preference help clicked");
        Context context = getActivity();
        AlertDialog ad = new AlertDialog.Builder(context).setTitle(R.string.help_dlg_title)
                .setMessage(R.string.help_dlg_message).setPositiveButton(android.R.string.ok, null).create();
        ad.show();
        Linkify.addLinks((TextView) ad.findViewById(android.R.id.message), Linkify.ALL);
        return true;
    });

    Preference about = findPref("about");
    about.setOnPreferenceClickListener(preference -> {
        startActivity(new Intent(getActivity(), AboutActivity.class));
        return true;
    });

}

From source file:com.ichi2.anki2.Reviewer.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    Resources res = getResources();

    UIUtils.addMenuItemInActionBar(menu, Menu.NONE, MENU_MARK, Menu.NONE, R.string.menu_mark_card,
            R.drawable.ic_menu_mark);/* w ww  .  j  av a2  s .c o m*/
    UIUtils.addMenuItemInActionBar(menu, Menu.NONE, MENU_UNDO, Menu.NONE, R.string.undo,
            R.drawable.ic_menu_revert_disabled);
    UIUtils.addMenuItem(menu, Menu.NONE, MENU_EDIT, Menu.NONE, R.string.menu_edit_card,
            R.drawable.ic_menu_edit);
    if (mPrefWhiteboard) {
        if (mShowWhiteboard) {
            UIUtils.addMenuItemInActionBar(menu, Menu.NONE, MENU_WHITEBOARD, Menu.NONE,
                    R.string.hide_whiteboard, R.drawable.ic_menu_compose);
        } else {
            UIUtils.addMenuItemInActionBar(menu, Menu.NONE, MENU_WHITEBOARD, Menu.NONE,
                    R.string.show_whiteboard, R.drawable.ic_menu_compose);
        }
        UIUtils.addMenuItemInActionBar(menu, Menu.NONE, MENU_CLEAR_WHITEBOARD, Menu.NONE,
                R.string.clear_whiteboard, R.drawable.ic_menu_clear_playlist);
    }

    if (mPrefRecord) {
        // TODO proper icon
        final MenuItem recorderItem = UIUtils.addMenuItem(menu, Menu.NONE, MENU_RECORD, Menu.NONE,
                Recorder.recording() ? R.string.record_stop : R.string.record_start,
                R.drawable.ic_circle_pressed);
        final MenuItem replayItem = UIUtils.addMenuItem(menu, Menu.NONE, MENU_RECORD_REPLAY, Menu.NONE,
                R.string.record_play, R.drawable.ic_circle_normal);
        // disable unless something is recorded
        replayItem.setEnabled(false);
        // set relevant listeners
        Recorder.setRecordingStartedListener(new Recorder.RecordingStartedListener() {

            @Override
            public void onRecordingStarted() {
                recorderItem.setTitle(R.string.record_stop);
            }
        });
        Recorder.setRecordingFinishedListener(new Recorder.RecordingFinishedListener() {

            @Override
            public void onRecordingFinished() {
                recorderItem.setTitle(R.string.record_start);
                replayItem.setEnabled(true);
            }
        });
        Recorder.setRecorderResetListener(new Recorder.RecorderResetListener() {

            @Override
            public void onRecorderReset() {
                replayItem.setEnabled(false);
            }
        });
    }

    SubMenu removeDeckSubMenu = menu.addSubMenu(Menu.NONE, MENU_REMOVE, Menu.NONE, R.string.menu_dismiss_note);
    removeDeckSubMenu.setIcon(R.drawable.ic_menu_stop);
    removeDeckSubMenu.add(Menu.NONE, MENU_REMOVE_BURY, Menu.NONE, R.string.menu_bury_note);
    removeDeckSubMenu.add(Menu.NONE, MENU_REMOVE_SUSPEND_CARD, Menu.NONE, R.string.menu_suspend_card);
    removeDeckSubMenu.add(Menu.NONE, MENU_REMOVE_SUSPEND_NOTE, Menu.NONE, R.string.menu_suspend_note);
    removeDeckSubMenu.add(Menu.NONE, MENU_REMOVE_DELETE, Menu.NONE, R.string.menu_delete_note);
    if (mPrefTextSelection) {
        MenuItem item = menu.add(Menu.NONE, MENU_SEARCH, Menu.NONE, res.getString(R.string.menu_select));
        item.setIcon(R.drawable.ic_menu_search);
        item.setEnabled(Lookup.isAvailable());
    }
    return true;
}

From source file:com.nit.vicky.CardBrowser.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    Themes.applyTheme(this);
    super.onCreate(savedInstanceState);

    View mainView = getLayoutInflater().inflate(R.layout.card_browser, null);
    setContentView(mainView);//from w w w .j  a  v a 2  s  .  c om
    Themes.setContentStyle(mainView, Themes.CALLER_CARDBROWSER);

    mCol = AnkiDroidApp.getCol();
    if (mCol == null) {
        reloadCollection(savedInstanceState);
        return;
    }
    mDeckNames = new HashMap<String, String>();
    for (long did : mCol.getDecks().allIds()) {
        mDeckNames.put(String.valueOf(did), mCol.getDecks().name(did));
    }
    registerExternalStorageListener();

    Intent i = getIntent();
    mWholeCollection = i.hasExtra("fromDeckpicker") && i.getBooleanExtra("fromDeckpicker", false);

    mBackground = Themes.getCardBrowserBackground();

    SharedPreferences preferences = AnkiDroidApp.getSharedPrefs(getBaseContext());
    int sflRelativeFontSize = preferences.getInt("relativeCardBrowserFontSize", DEFAULT_FONT_SIZE_RATIO);
    String sflCustomFont = preferences.getString("browserEditorFont", "");
    mPrefFixArabic = preferences.getBoolean("fixArabicText", false);

    Resources res = getResources();
    mOrderByFields = res.getStringArray(R.array.card_browser_order_labels);
    try {
        mOrder = CARD_ORDER_NONE;
        String colOrder = mCol.getConf().getString("sortType");
        for (int c = 0; c < fSortTypes.length; ++c) {
            if (fSortTypes[c].equals(colOrder)) {
                mOrder = c;
                break;
            }
        }
        if (mOrder == 1 && preferences.getBoolean("cardBrowserNoSorting", false)) {
            mOrder = 0;
        }
        mOrderAsc = Upgrade.upgradeJSONIfNecessary(mCol, mCol.getConf(), "sortBackwards", false);
        // default to descending for non-text fields
        if (fSortTypes[mOrder].equals("noteFld")) {
            mOrderAsc = !mOrderAsc;
        }
    } catch (JSONException e) {
        throw new RuntimeException(e);
    }

    mCards = new ArrayList<HashMap<String, String>>();
    mCardsListView = (ListView) findViewById(R.id.card_browser_list);

    mCardsAdapter = new SizeControlledListAdapter(this, mCards, R.layout.card_item,
            new String[] { "word", "sfld", "deck", "flags" },
            new int[] { R.id.card_word, R.id.card_sfld, R.id.card_deck, R.id.card_item }, sflRelativeFontSize,
            sflCustomFont);
    mCardsAdapter.setViewBinder(new SimpleAdapter.ViewBinder() {
        @Override
        public boolean setViewValue(View view, Object arg1, String text) {
            if (view.getId() == R.id.card_item) {
                int which = BACKGROUND_NORMAL;
                if (text.equals("1")) {
                    which = BACKGROUND_SUSPENDED;
                } else if (text.equals("2")) {
                    which = BACKGROUND_MARKED;
                } else if (text.equals("3")) {
                    which = BACKGROUND_MARKED_SUSPENDED;
                }
                view.setBackgroundResource(mBackground[which]);
                return true;
            } else if (view.getId() == R.id.card_deck && text.length() > 0) {
                view.setVisibility(View.VISIBLE);
            }
            return false;
        }
    });

    //mCardsListView.setAdapter(mCardsAdapter);
    mCardsListView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            mPositionInCardsList = position;
            long cardId = Long.parseLong(mCards.get(mPositionInCardsList).get("id"));
            sCardBrowserCard = mCol.getCard(cardId);
            Intent editCard = new Intent(CardBrowser.this, MultimediaCardEditorActivity.class);
            //editCard.putExtra(CardEditor.EXTRA_CALLER, CardEditor.CALLER_CARDBROWSER_EDIT);
            editCard.putExtra(MultimediaCardEditorActivity.EXTRA_CARD_ID, sCardBrowserCard.getId());
            startActivityForResult(editCard, EDIT_CARD);
            if (AnkiDroidApp.SDK_VERSION > 4) {
                ActivityTransitionAnimation.slide(CardBrowser.this, ActivityTransitionAnimation.LEFT);
            }
        }
    });
    registerForContextMenu(mCardsListView);

    mCardsGridView = (StaggeredGridView) findViewById(R.id.card_browser_gridview);
    mCardsGridView.setAdapter(mGridAdapter);
    mCardsGridView.setOnItemClickListener(new StaggeredGridView.OnItemClickListener() {
        @Override
        public void onItemClick(StaggeredGridView parent, View view, int position, long id) {
            mPositionInCardsList = position;
            long cardId = Long.parseLong(mCards.get(mPositionInCardsList).get("id"));
            sCardBrowserCard = mCol.getCard(cardId);
            Intent editCard = new Intent(CardBrowser.this, MultimediaCardEditorActivity.class);
            //editCard.putExtra(CardEditor.EXTRA_CALLER, CardEditor.CALLER_CARDBROWSER_EDIT);
            editCard.putExtra(MultimediaCardEditorActivity.EXTRA_CARD_ID, sCardBrowserCard.getId());
            startActivityForResult(editCard, EDIT_CARD);
            if (AnkiDroidApp.SDK_VERSION > 4) {
                ActivityTransitionAnimation.slide(CardBrowser.this, ActivityTransitionAnimation.LEFT);
            }
            String imgURL = getImgURL(sCardBrowserCard);
            Toast.makeText(CardBrowser.this, imgURL, Toast.LENGTH_LONG).show();
        }
    });
    mSearchEditText = (EditText) findViewById(R.id.card_browser_search);
    mSearchEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView view, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                onSearch();
                return true;
            }
            return false;
        }
    });
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    mSearchButton = (ImageButton) findViewById(R.id.card_browser_search_button);
    mSearchButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onSearch();
        }
    });

    mSearchTerms = "";
    if (mWholeCollection) {
        mRestrictOnDeck = "";
        setTitle(res.getString(R.string.card_browser_all_decks));
    } else {
        try {
            String deckName = mCol.getDecks().current().getString("name");
            mRestrictOnDeck = "deck:'" + deckName + "' ";
            setTitle(deckName);
        } catch (JSONException e) {
            throw new RuntimeException(e);
        }
    }

    mSelectedTags = new HashSet<String>();

    if (!preferences.getBoolean("cardBrowserNoSearchOnOpen", false)) {
        searchCards();
    }
}

From source file:carnero.cgeo.original.libs.Base.java

public boolean runNavigation(Activity activity, Resources res, Settings settings, Warning warning,
        GoogleAnalyticsTracker tracker, Double latitude, Double longitude, Double latitudeNow,
        Double longitudeNow) {//from  w ww  .ja v  a  2 s.  c om
    if (activity == null) {
        return false;
    }
    if (settings == null) {
        return false;
    }

    // Google Navigation
    if (settings.useGNavigation == 1) {
        try {
            activity.startActivity(new Intent(Intent.ACTION_VIEW,
                    Uri.parse("google.navigation:ll=" + latitude + "," + longitude)));

            sendAnal(activity, tracker, "/external/native/navigation");

            return true;
        } catch (Exception e) {
            // nothing
        }
    }

    // Google Maps Directions
    try {
        if (latitudeNow != null && longitudeNow != null) {
            activity.startActivity(
                    new Intent(Intent.ACTION_VIEW, Uri.parse("http://maps.google.com/maps?f=d&saddr="
                            + latitudeNow + "," + longitudeNow + "&daddr=" + latitude + "," + longitude)));
        } else {
            activity.startActivity(new Intent(Intent.ACTION_VIEW,
                    Uri.parse("http://maps.google.com/maps?f=d&daddr=" + latitude + "," + longitude)));
        }

        sendAnal(activity, tracker, "/external/native/maps");

        return true;
    } catch (Exception e) {
        // nothing
    }

    Log.i(Settings.tag, "cgBase.runNavigation: No navigation application available.");

    if (warning != null && res != null) {
        warning.showToast(res.getString(R.string.err_navigation_no));
    }

    return false;
}

From source file:carnero.cgeo.cgBase.java

public boolean runNavigation(Activity activity, Resources res, cgSettings settings, cgWarning warning,
        GoogleAnalyticsTracker tracker, Double latitude, Double longitude, Double latitudeNow,
        Double longitudeNow) {/*from  w ww .j  ava  2  s . c o  m*/
    if (activity == null) {
        return false;
    }
    if (settings == null) {
        return false;
    }

    // Google Navigation
    if (settings.useGNavigation == 1) {
        try {
            activity.startActivity(new Intent(Intent.ACTION_VIEW,
                    Uri.parse("google.navigation:ll=" + latitude + "," + longitude)));

            sendAnal(activity, tracker, "/external/native/navigation");

            return true;
        } catch (Exception e) {
            // nothing
        }
    }

    // Google Maps Directions
    try {
        if (latitudeNow != null && longitudeNow != null) {
            activity.startActivity(
                    new Intent(Intent.ACTION_VIEW, Uri.parse("http://maps.google.com/maps?f=d&saddr="
                            + latitudeNow + "," + longitudeNow + "&daddr=" + latitude + "," + longitude)));
        } else {
            activity.startActivity(new Intent(Intent.ACTION_VIEW,
                    Uri.parse("http://maps.google.com/maps?f=d&daddr=" + latitude + "," + longitude)));
        }

        sendAnal(activity, tracker, "/external/native/maps");

        return true;
    } catch (Exception e) {
        // nothing
    }

    Log.i(cgSettings.tag, "cgBase.runNavigation: No navigation application available.");

    if (warning != null && res != null) {
        warning.showToast(res.getString(R.string.err_navigation_no));
    }

    return false;
}

From source file:carnero.cgeo.original.libs.Base.java

public boolean runExternalMap(int application, Activity activity, Resources res, Warning warning,
        GoogleAnalyticsTracker tracker, Cache cache, Waypoint waypoint, Double latitude, Double longitude) {
    if (cache == null && waypoint == null && latitude == null && longitude == null) {
        return false;
    }/*from  w  w  w  .ja va 2s .c  o m*/

    if (application == mapAppLocus) {
        // locus
        try {
            final Intent intentTest = new Intent(Intent.ACTION_VIEW);
            intentTest.setData(Uri.parse("menion.points:x"));

            if (isIntentAvailable(activity, intentTest) == true) {
                final ArrayList<Waypoint> waypoints = new ArrayList<Waypoint>();
                // get only waypoints with coordinates
                if (cache != null && cache.waypoints != null && cache.waypoints.isEmpty() == false) {
                    for (Waypoint wp : cache.waypoints) {
                        if (wp.latitude != null && wp.longitude != null) {
                            waypoints.add(wp);
                        }
                    }
                }

                final ByteArrayOutputStream baos = new ByteArrayOutputStream();
                final DataOutputStream dos = new DataOutputStream(baos);

                dos.writeInt(1); // not used
                if (cache != null) {
                    if (waypoints == null || waypoints.isEmpty() == true) {
                        dos.writeInt(1); // cache only
                    } else {
                        dos.writeInt((1 + waypoints.size())); // cache and waypoints
                    }
                } else {
                    dos.writeInt(1); // one waypoint
                }

                int icon = -1;
                if (cache != null) {
                    icon = getIcon(true, cache.type, cache.own, cache.found, cache.disabled || cache.archived);
                } else if (waypoint != null) {
                    icon = getIcon(false, waypoint.type, false, false, false);
                } else {
                    icon = getIcon(false, "waypoint", false, false, false);
                }

                if (icon > 0) {
                    // load icon
                    Bitmap bitmap = BitmapFactory.decodeResource(res, icon);
                    ByteArrayOutputStream baos2 = new ByteArrayOutputStream();
                    bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos2);
                    byte[] image = baos2.toByteArray();

                    dos.writeInt(image.length);
                    dos.write(image);
                } else {
                    // no icon
                    dos.writeInt(0); // no image
                }

                // name
                if (cache != null && cache.name != null && cache.name.length() > 0) {
                    dos.writeUTF(cache.name);
                } else if (waypoint != null && waypoint.name != null && waypoint.name.length() > 0) {
                    dos.writeUTF(waypoint.name);
                } else {
                    dos.writeUTF("");
                }

                // description
                if (cache != null && cache.geocode != null && cache.geocode.length() > 0) {
                    dos.writeUTF(cache.geocode.toUpperCase());
                } else if (waypoint != null && waypoint.lookup != null && waypoint.lookup.length() > 0) {
                    dos.writeUTF(waypoint.lookup.toUpperCase());
                } else {
                    dos.writeUTF("");
                }

                // additional data :: keyword, button title, package, activity, data name, data content
                if (cache != null && cache.geocode != null && cache.geocode.length() > 0) {
                    dos.writeUTF("intent;c:geo;carnero.cgeo;carnero.cgeo.cgeodetail;geocode;" + cache.geocode);
                } else if (waypoint != null && waypoint.id != null && waypoint.id > 0) {
                    dos.writeUTF("intent;c:geo;carnero.cgeo;carnero.cgeo.cgeowaypoint;id;" + waypoint.id);
                } else {
                    dos.writeUTF("");
                }

                if (cache != null && cache.latitude != null && cache.longitude != null) {
                    dos.writeDouble(cache.latitude); // latitude
                    dos.writeDouble(cache.longitude); // longitude
                } else if (waypoint != null && waypoint.latitude != null && waypoint.longitude != null) {
                    dos.writeDouble(waypoint.latitude); // latitude
                    dos.writeDouble(waypoint.longitude); // longitude
                } else {
                    dos.writeDouble(latitude); // latitude
                    dos.writeDouble(longitude); // longitude
                }

                // cache waypoints
                if (waypoints != null && waypoints.isEmpty() == false) {
                    for (Waypoint wp : waypoints) {
                        if (wp == null || wp.latitude == null || wp.longitude == null) {
                            continue;
                        }

                        final int wpIcon = getIcon(false, wp.type, false, false, false);

                        if (wpIcon > 0) {
                            // load icon
                            Bitmap bitmap = BitmapFactory.decodeResource(res, wpIcon);
                            ByteArrayOutputStream baos2 = new ByteArrayOutputStream();
                            bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos2);
                            byte[] image = baos2.toByteArray();

                            dos.writeInt(image.length);
                            dos.write(image);
                        } else {
                            // no icon
                            dos.writeInt(0); // no image
                        }

                        // name
                        if (wp.lookup != null && wp.lookup.length() > 0) {
                            dos.writeUTF(wp.lookup.toUpperCase());
                        } else {
                            dos.writeUTF("");
                        }

                        // description
                        if (wp.name != null && wp.name.length() > 0) {
                            dos.writeUTF(wp.name);
                        } else {
                            dos.writeUTF("");
                        }

                        // additional data :: keyword, button title, package, activity, data name, data content
                        if (wp.id != null && wp.id > 0) {
                            dos.writeUTF("intent;c:geo;carnero.cgeo;carnero.cgeo.cgeowaypoint;id;" + wp.id);
                        } else {
                            dos.writeUTF("");
                        }

                        dos.writeDouble(wp.latitude); // latitude
                        dos.writeDouble(wp.longitude); // longitude
                    }
                }

                final Intent intent = new Intent();
                intent.setAction(Intent.ACTION_VIEW);
                intent.setData(Uri.parse("menion.points:data"));
                intent.putExtra("data", baos.toByteArray());

                activity.startActivity(intent);

                sendAnal(activity, tracker, "/external/locus");

                return true;
            }
        } catch (Exception e) {
            // nothing
        }
    }

    if (application == mapAppRmaps) {
        // rmaps
        try {
            final Intent intent = new Intent("com.robert.maps.action.SHOW_POINTS");

            if (isIntentAvailable(activity, intent) == true) {
                final ArrayList<String> locations = new ArrayList<String>();
                if (cache != null && cache.latitude != null && cache.longitude != null) {
                    locations.add(String.format((Locale) null, "%.6f", cache.latitude) + ","
                            + String.format((Locale) null, "%.6f", cache.longitude) + ";" + cache.geocode + ";"
                            + cache.name);
                } else if (waypoint != null && waypoint.latitude != null && waypoint.longitude != null) {
                    locations.add(String.format((Locale) null, "%.6f", waypoint.latitude) + ","
                            + String.format((Locale) null, "%.6f", waypoint.longitude) + ";" + waypoint.lookup
                            + ";" + waypoint.name);
                }

                intent.putStringArrayListExtra("locations", locations);

                activity.startActivity(intent);

                sendAnal(activity, tracker, "/external/rmaps");

                return true;
            }
        } catch (Exception e) {
            // nothing
        }
    }

    if (application == mapAppAny) {
        // fallback
        try {
            if (cache != null && cache.latitude != null && cache.longitude != null) {
                activity.startActivity(new Intent(Intent.ACTION_VIEW,
                        Uri.parse("geo:" + cache.latitude + "," + cache.longitude)));
                // INFO: q parameter works with Google Maps, but breaks cooperation with all other apps
            } else if (waypoint != null && waypoint.latitude != null && waypoint.longitude != null) {
                activity.startActivity(new Intent(Intent.ACTION_VIEW,
                        Uri.parse("geo:" + waypoint.latitude + "," + waypoint.longitude)));
                // INFO: q parameter works with Google Maps, but breaks cooperation with all other apps
            }

            sendAnal(activity, tracker, "/external/native/maps");

            return true;
        } catch (Exception e) {
            // nothing
        }
    }

    Log.i(Settings.tag, "cgBase.runExternalMap: No maps application available.");

    if (warning != null && res != null) {
        warning.showToast(res.getString(R.string.err_application_no));
    }

    return false;
}

From source file:carnero.cgeo.cgBase.java

public boolean runExternalMap(int application, Activity activity, Resources res, cgWarning warning,
        GoogleAnalyticsTracker tracker, cgCache cache, cgWaypoint waypoint, Double latitude, Double longitude) {
    if (cache == null && waypoint == null && latitude == null && longitude == null) {
        return false;
    }/*from   w w w .j  a va 2s.  c o  m*/

    if (application == mapAppLocus) {
        // locus
        try {
            final Intent intentTest = new Intent(Intent.ACTION_VIEW);
            intentTest.setData(Uri.parse("menion.points:x"));

            if (isIntentAvailable(activity, intentTest) == true) {
                final ArrayList<cgWaypoint> waypoints = new ArrayList<cgWaypoint>();
                // get only waypoints with coordinates
                if (cache != null && cache.waypoints != null && cache.waypoints.isEmpty() == false) {
                    for (cgWaypoint wp : cache.waypoints) {
                        if (wp.latitude != null && wp.longitude != null) {
                            waypoints.add(wp);
                        }
                    }
                }

                final ByteArrayOutputStream baos = new ByteArrayOutputStream();
                final DataOutputStream dos = new DataOutputStream(baos);

                dos.writeInt(1); // not used
                if (cache != null) {
                    if (waypoints == null || waypoints.isEmpty() == true) {
                        dos.writeInt(1); // cache only
                    } else {
                        dos.writeInt((1 + waypoints.size())); // cache and waypoints
                    }
                } else {
                    dos.writeInt(1); // one waypoint
                }

                int icon = -1;
                if (cache != null) {
                    icon = getIcon(true, cache.type, cache.own, cache.found, cache.disabled || cache.archived);
                } else if (waypoint != null) {
                    icon = getIcon(false, waypoint.type, false, false, false);
                } else {
                    icon = getIcon(false, "waypoint", false, false, false);
                }

                if (icon > 0) {
                    // load icon
                    Bitmap bitmap = BitmapFactory.decodeResource(res, icon);
                    ByteArrayOutputStream baos2 = new ByteArrayOutputStream();
                    bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos2);
                    byte[] image = baos2.toByteArray();

                    dos.writeInt(image.length);
                    dos.write(image);
                } else {
                    // no icon
                    dos.writeInt(0); // no image
                }

                // name
                if (cache != null && cache.name != null && cache.name.length() > 0) {
                    dos.writeUTF(cache.name);
                } else if (waypoint != null && waypoint.name != null && waypoint.name.length() > 0) {
                    dos.writeUTF(waypoint.name);
                } else {
                    dos.writeUTF("");
                }

                // description
                if (cache != null && cache.geocode != null && cache.geocode.length() > 0) {
                    dos.writeUTF(cache.geocode.toUpperCase());
                } else if (waypoint != null && waypoint.lookup != null && waypoint.lookup.length() > 0) {
                    dos.writeUTF(waypoint.lookup.toUpperCase());
                } else {
                    dos.writeUTF("");
                }

                // additional data :: keyword, button title, package, activity, data name, data content
                if (cache != null && cache.geocode != null && cache.geocode.length() > 0) {
                    dos.writeUTF("intent;c:geo;carnero.cgeo;carnero.cgeo.cgeodetail;geocode;" + cache.geocode);
                } else if (waypoint != null && waypoint.id != null && waypoint.id > 0) {
                    dos.writeUTF("intent;c:geo;carnero.cgeo;carnero.cgeo.cgeowaypoint;id;" + waypoint.id);
                } else {
                    dos.writeUTF("");
                }

                if (cache != null && cache.latitude != null && cache.longitude != null) {
                    dos.writeDouble(cache.latitude); // latitude
                    dos.writeDouble(cache.longitude); // longitude
                } else if (waypoint != null && waypoint.latitude != null && waypoint.longitude != null) {
                    dos.writeDouble(waypoint.latitude); // latitude
                    dos.writeDouble(waypoint.longitude); // longitude
                } else {
                    dos.writeDouble(latitude); // latitude
                    dos.writeDouble(longitude); // longitude
                }

                // cache waypoints
                if (waypoints != null && waypoints.isEmpty() == false) {
                    for (cgWaypoint wp : waypoints) {
                        if (wp == null || wp.latitude == null || wp.longitude == null) {
                            continue;
                        }

                        final int wpIcon = getIcon(false, wp.type, false, false, false);

                        if (wpIcon > 0) {
                            // load icon
                            Bitmap bitmap = BitmapFactory.decodeResource(res, wpIcon);
                            ByteArrayOutputStream baos2 = new ByteArrayOutputStream();
                            bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos2);
                            byte[] image = baos2.toByteArray();

                            dos.writeInt(image.length);
                            dos.write(image);
                        } else {
                            // no icon
                            dos.writeInt(0); // no image
                        }

                        // name
                        if (wp.lookup != null && wp.lookup.length() > 0) {
                            dos.writeUTF(wp.lookup.toUpperCase());
                        } else {
                            dos.writeUTF("");
                        }

                        // description
                        if (wp.name != null && wp.name.length() > 0) {
                            dos.writeUTF(wp.name);
                        } else {
                            dos.writeUTF("");
                        }

                        // additional data :: keyword, button title, package, activity, data name, data content
                        if (wp.id != null && wp.id > 0) {
                            dos.writeUTF("intent;c:geo;carnero.cgeo;carnero.cgeo.cgeowaypoint;id;" + wp.id);
                        } else {
                            dos.writeUTF("");
                        }

                        dos.writeDouble(wp.latitude); // latitude
                        dos.writeDouble(wp.longitude); // longitude
                    }
                }

                final Intent intent = new Intent();
                intent.setAction(Intent.ACTION_VIEW);
                intent.setData(Uri.parse("menion.points:data"));
                intent.putExtra("data", baos.toByteArray());

                activity.startActivity(intent);

                sendAnal(activity, tracker, "/external/locus");

                return true;
            }
        } catch (Exception e) {
            // nothing
        }
    }

    if (application == mapAppRmaps) {
        // rmaps
        try {
            final Intent intent = new Intent("com.robert.maps.action.SHOW_POINTS");

            if (isIntentAvailable(activity, intent) == true) {
                final ArrayList<String> locations = new ArrayList<String>();
                if (cache != null && cache.latitude != null && cache.longitude != null) {
                    locations.add(String.format((Locale) null, "%.6f", cache.latitude) + ","
                            + String.format((Locale) null, "%.6f", cache.longitude) + ";" + cache.geocode + ";"
                            + cache.name);
                } else if (waypoint != null && waypoint.latitude != null && waypoint.longitude != null) {
                    locations.add(String.format((Locale) null, "%.6f", waypoint.latitude) + ","
                            + String.format((Locale) null, "%.6f", waypoint.longitude) + ";" + waypoint.lookup
                            + ";" + waypoint.name);
                }

                intent.putStringArrayListExtra("locations", locations);

                activity.startActivity(intent);

                sendAnal(activity, tracker, "/external/rmaps");

                return true;
            }
        } catch (Exception e) {
            // nothing
        }
    }

    if (application == mapAppAny) {
        // fallback
        try {
            if (cache != null && cache.latitude != null && cache.longitude != null) {
                activity.startActivity(new Intent(Intent.ACTION_VIEW,
                        Uri.parse("geo:" + cache.latitude + "," + cache.longitude)));
                // INFO: q parameter works with Google Maps, but breaks cooperation with all other apps
            } else if (waypoint != null && waypoint.latitude != null && waypoint.longitude != null) {
                activity.startActivity(new Intent(Intent.ACTION_VIEW,
                        Uri.parse("geo:" + waypoint.latitude + "," + waypoint.longitude)));
                // INFO: q parameter works with Google Maps, but breaks cooperation with all other apps
            }

            sendAnal(activity, tracker, "/external/native/maps");

            return true;
        } catch (Exception e) {
            // nothing
        }
    }

    Log.i(cgSettings.tag, "cgBase.runExternalMap: No maps application available.");

    if (warning != null && res != null) {
        warning.showToast(res.getString(R.string.err_application_no));
    }

    return false;
}