@Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    setContentView(R.layout.search_venues_activity);
    setDefaultKeyMode(Activity.DEFAULT_KEYS_SEARCH_LOCAL);
    registerReceiver(mLoggedOutReceiver, new IntentFilter(Foursquared.INTENT_ACTION_LOGGED_OUT));

    searchResultsObservable = new SearchResultsObservable();

    initTabHost();
    initListViewAdapter();

    // Watch to see if we've been called as a shortcut intent.
    mIsShortcutPicker = Intent.ACTION_CREATE_SHORTCUT.equals(getIntent().getAction());

    if (getLastNonConfigurationInstance() != null) {
      if (DEBUG) Log.d(TAG, "Restoring state.");
      SearchHolder holder = (SearchHolder) getLastNonConfigurationInstance();
      if (holder.results != null) {
        mSearchHolder.query = holder.query;
        setSearchResults(holder.results);
        putSearchResultsInAdapter(holder.results);
      }
    } else {
      onNewIntent(getIntent());
    }
  }
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.planner);
    // If the activity was started with the "create shortcut" action, we
    // remember this to change the behavior upon a search.
    if (Intent.ACTION_CREATE_SHORTCUT.equals(getIntent().getAction())) {
      mCreateShortcut = true;
    }

    mFromButton = (Button) findViewById(R.id.from);
    mFromButton.setOnClickListener(_fromListener);
    mToButton = (Button) findViewById(R.id.to);
    mToButton.setOnClickListener(_toListener);

    mHistoryDbAdapter = new HistoryDbAdapter(this).open();
    mFromButton.setText(mHistoryDbAdapter.fetchLastStartPoint());
    mToButton.setText(mHistoryDbAdapter.fecthLastEndPoint());

    mSearchNowButton = (Button) findViewById(R.id.search_now);
    mSearchNowButton.setOnClickListener(_searchNowListener);
    mSearchLaterButton = (Button) findViewById(R.id.search_later);
    mSearchLaterButton.setOnClickListener(_searchLaterListener);

    mReverseButton = (ImageButton) findViewById(R.id.reverse);
    mReverseButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            reverse();
            Tracker.trackPageView("Reverse");
          }
        });
    Tracker.trackPageView("Planner");
  }
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle icicle) {

    boolean abort = false;

    try {
      // handle java.lang.NoClassDefFoundError
      super.onCreate(icicle);
    } catch (Throwable t) {
      ACRA.getErrorReporter().handleSilentException(t);
      IntentsHelper.getInstance().setActivity(this);
      IntentsHelper.getInstance().showInfoToast("Sorry. Your device is currently unsupported :(");
      abort = true;
    }

    if (!abort) {
      final Intent intent = getIntent();
      final String action = intent.getAction();
      // If the intent is a request to create a shortcut, we'll do that and exit
      if (Intent.ACTION_CREATE_SHORTCUT.equals(action)) {
        IntentsHelper.getInstance().setActivity(this);
        IntentsHelper.getInstance().setupShortcut();
        abort = true;
      } else {
        long lastStartupTime =
            ConfigurationManager.getInstance().getLong(ConfigurationManager.LAST_STARTING_DATE);
        LoggerUtils.debug(
            "Last startup time is: "
                + DateTimeUtils.getDefaultDateTimeString(
                    lastStartupTime, ConfigurationManager.getInstance().getCurrentLocale()));
        ConfigurationManager.getInstance()
            .putLong(ConfigurationManager.LAST_STARTING_DATE, System.currentTimeMillis());

        Intent mapActivity;
        if (OsUtil.isHoneycombOrHigher()) {
          if (GoogleApiAvailability.getInstance()
                      .isGooglePlayServicesAvailable(getApplicationContext())
                  == ConnectionResult.SUCCESS
              && ConfigurationManager.getInstance().getInt(ConfigurationManager.MAP_PROVIDER)
                  == ConfigurationManager.GOOGLE_MAPS) {
            mapActivity = new Intent(this, GMSClient3MainActivity.class);
          } else {
            ConfigurationManager.getInstance()
                .putInteger(ConfigurationManager.MAP_PROVIDER, ConfigurationManager.OSM_MAPS);
            mapActivity = new Intent(this, GMSClient2OSMMainActivity.class);
          }
          startActivity(mapActivity);
        } else {
          IntentsHelper.getInstance()
              .showInfoToast("This application requires Android 3.0 or higher to run!");
        }
      }
    }

    if (abort) {
      finish();
    }
  }
    @Override
    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);

        final Intent intent = getIntent();
        final String action = intent.getAction();

        // The Android needs to know what shortcuts are available, generate the list
        if (Intent.ACTION_CREATE_SHORTCUT.equals(action)) {
            buildMenuList();
        }
    }
  /** Create a new BrowserBookmarksPage. */
  @Override
  protected void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    // Grab the app icon size as a resource.
    mIconSize = getResources().getDimensionPixelSize(android.R.dimen.app_icon_size);

    Intent intent = getIntent();
    if (Intent.ACTION_CREATE_SHORTCUT.equals(intent.getAction())) {
      mCreateShortcut = true;
    }
    mDisableNewWindow = intent.getBooleanExtra("disable_new_window", false);
    mMostVisited = intent.getBooleanExtra("mostVisited", false);

    if (mCreateShortcut) {
      setTitle(R.string.browser_bookmarks_page_bookmarks_text);
    }

    setContentView(R.layout.empty_history);
    mEmptyView = findViewById(R.id.empty_view);
    mEmptyView.setVisibility(View.GONE);

    SharedPreferences p = getPreferences(MODE_PRIVATE);

    // See if the user has set a preference for the view mode of their
    // bookmarks. Otherwise default to grid mode.
    BookmarkViewMode preference = BookmarkViewMode.NONE;
    if (mMostVisited) {
      // For the most visited page, only use list mode.
      preference = BookmarkViewMode.LIST;
    } else {
      preference =
          BookmarkViewMode.values()[
              p.getInt(PREF_BOOKMARK_VIEW_MODE, BookmarkViewMode.GRID.ordinal())];
    }
    switchViewMode(preference);

    final boolean createShortcut = mCreateShortcut;
    final boolean mostVisited = mMostVisited;
    final String url = intent.getStringExtra("url");
    final String title = intent.getStringExtra("title");
    final Bitmap thumbnail = (Bitmap) intent.getParcelableExtra("thumbnail");
    new AsyncTask<Void, Void, Void>() {
      @Override
      protected Void doInBackground(Void... unused) {
        BrowserBookmarksAdapter adapter =
            new BrowserBookmarksAdapter(
                BrowserBookmarksPage.this, url, title, thumbnail, createShortcut, mostVisited);
        mHandler.obtainMessage(ADAPTER_CREATED, adapter).sendToTarget();
        return null;
      }
    }.execute();
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    if (Intent.ACTION_VIEW.equals(getIntent().getAction())
        || Intent.ACTION_SEND.equals(getIntent().getAction())
        || Intent.ACTION_SENDTO.equals(getIntent().getAction())
        || Intent.ACTION_CREATE_SHORTCUT.equals(getIntent().getAction())) {
      ActivityManager.getInstance().startNewTask(this);
    }
    super.onCreate(savedInstanceState);

    if (isFinishing()) {
      return;
    }

    setContentView(R.layout.contact_list);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_default);
    toolbar.setOnClickListener(this);

    drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawerToggle =
        new ActionBarDrawerToggle(
            this,
            drawerLayout,
            toolbar,
            R.string.application_title_short,
            R.string.application_title_short);
    drawerLayout.setDrawerListener(drawerToggle);

    toolbar.inflateMenu(R.menu.contact_list);
    optionsMenu = toolbar.getMenu();
    setUpSearchView(optionsMenu);
    toolbar.setOnMenuItemClickListener(this);

    barPainter = new BarPainter(this, toolbar);
    barPainter.setDefaultColor();

    toolbar.setTitle(R.string.application_title_full);

    if (savedInstanceState != null) {
      sendText = savedInstanceState.getString(SAVED_SEND_TEXT);
      action = savedInstanceState.getString(SAVED_ACTION);
    } else {
      getSupportFragmentManager()
          .beginTransaction()
          .add(R.id.container, new ContactListFragment(), CONTACT_LIST_TAG)
          .commit();

      sendText = null;
      action = getIntent().getAction();
    }
    getIntent().setAction(null);
  }
Esempio n. 7
0
  @Override
  public void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    // finish() immediately if we aren't supposed to be here
    if (!Intent.ACTION_CREATE_SHORTCUT.equals(getIntent().getAction())) {
      finish();
      return;
    }

    setContentView(R.layout.launcher_shortcuts);
    ListView listView = getListView();
    listView.setOnItemClickListener(this);
    listView.setItemsCanFocus(false);

    refresh();
  }
  @Override
  public void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    // TODO Relax this test slightly in order to re-use this activity for widget creation
    if (!Intent.ACTION_CREATE_SHORTCUT.equals(getIntent().getAction())) {
      // finish() immediately if we aren't supposed to be here
      finish();
      return;
    }

    // Set handler for the "cancel" button
    setContentView(R.layout.account_shortcut_picker);
    findViewById(R.id.cancel).setOnClickListener(this);

    if (getFragmentManager().findFragmentById(R.id.shortcut_list) == null) {
      // Load the account picking fragment if we haven't created a fragment yet
      // NOTE: do not add to history as this will be the first fragment in the flow
      AccountShortcutPickerFragment fragment = new AccountShortcutPickerFragment();
      getFragmentManager().beginTransaction().add(R.id.shortcut_list, fragment).commit();
    }
  }
Esempio n. 9
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.add_task);

    ArrayList<Task> tasks;
    try {
      tasks = TodoUtil.loadTasksFromFile();
    } catch (IOException e) {
      Log.e(TAG, e.getMessage(), e);
      tasks = new ArrayList<Task>();
    }

    final Intent intent = getIntent();
    final String action = intent.getAction();
    // create shortcut and exit
    // create shortcut and exit
    if (Intent.ACTION_CREATE_SHORTCUT.equals(action)) {
      Log.d(TAG, "Setting up shortcut icon");
      setupShortcut();
      finish();
      return;
    } else if (Intent.ACTION_SEND.equals(action)) {
      Log.d(TAG, "Share");
      share_text = (String) intent.getCharSequenceExtra(Intent.EXTRA_TEXT);
      Log.d(TAG, share_text);
    }

    m_app = (TodoApplication) getApplication();
    // title bar label
    titleBarLabel = (TextView) findViewById(R.id.title_bar_label);

    // text
    final EditText textInputField = (EditText) findViewById(R.id.taskText);
    textInputField.setGravity(Gravity.TOP);

    if (share_text != null) {
      textInputField.setText(share_text);
    }

    Task task = (Task) getIntent().getSerializableExtra(Constants.EXTRA_TASK);
    if (task != null) {
      m_backup = task;
      textInputField.setText(task.inFileFormat());
      setTitle(R.string.update);
      titleBarLabel.setText(R.string.update);
    } else {
      setTitle(R.string.addtask);
      titleBarLabel.setText(R.string.addtask);
    }

    textInputField.setSelection(textInputField.getText().toString().length());

    // priorities
    priorities = (Spinner) findViewById(R.id.priorities);
    final ArrayList<String> prioArr = new ArrayList<String>();
    prioArr.add("Priority");
    prioArr.addAll(Priority.rangeInCode(Priority.A, Priority.E));
    priorities.setAdapter(Util.newSpinnerAdapter(this, prioArr));
    if (m_backup != null) {
      int index = prioArr.indexOf(m_backup.getPriority().getCode());
      priorities.setSelection(index < 0 ? 0 : index);
    }
    priorities.setOnItemSelectedListener(
        new OnItemSelectedListener() {
          @Override
          public void onItemSelected(AdapterView<?> arg0, View arg1, int position, long id) {
            int cursorPosition = textInputField.getSelectionStart();
            String currentText = textInputField.getText().toString();
            Priority priority = Priority.NONE;
            if (position > 0) {
              String item = prioArr.get(position);
              char p = item.charAt(0);
              priority = Priority.toPriority(p);
            }
            String text = PriorityTextSplitter.getInstance().split(currentText).text;
            textInputField.setText(Strings.insertPadded(text, 0, priority.inFileFormat()));
            textInputField.setSelection(
                CursorPositionCalculator.calculate(
                    cursorPosition, currentText, textInputField.getText().toString()));
          }

          @Override
          public void onNothingSelected(AdapterView<?> arg0) {}
        });

    // projects
    projects = (Spinner) findViewById(R.id.projects);
    final ArrayList<String> projectsArr = TaskHelper.getProjects(tasks);
    projectsArr.add(0, "Project");
    projects.setAdapter(Util.newSpinnerAdapter(this, projectsArr));
    projects.setOnItemSelectedListener(
        new OnItemSelectedListener() {
          @Override
          public void onItemSelected(AdapterView<?> arg0, View arg1, int position, long id) {
            if (position > 0) {
              int cursorPosition = textInputField.getSelectionStart();
              String currentText = textInputField.getText().toString();
              String item = "+" + projectsArr.get(position);
              textInputField.setText(Strings.insertPadded(currentText, cursorPosition, item));
              textInputField.setSelection(
                  CursorPositionCalculator.calculate(
                      cursorPosition, currentText, textInputField.getText().toString()));
            }
            projects.setSelection(0);
          }

          @Override
          public void onNothingSelected(AdapterView<?> arg0) {}
        });

    // contexts
    contexts = (Spinner) findViewById(R.id.contexts);
    final ArrayList<String> contextsArr = TaskHelper.getContexts(tasks);
    contextsArr.add(0, "Context");
    contexts.setAdapter(Util.newSpinnerAdapter(this, contextsArr));
    contexts.setOnItemSelectedListener(
        new OnItemSelectedListener() {
          @Override
          public void onItemSelected(AdapterView<?> arg0, View arg1, int position, long id) {
            if (position > 0) {
              int cursorPosition = textInputField.getSelectionStart();
              String currentText = textInputField.getText().toString();
              String item = "@" + contextsArr.get(position);
              textInputField.setText(Strings.insertPadded(currentText, cursorPosition, item));
              textInputField.setSelection(
                  CursorPositionCalculator.calculate(
                      cursorPosition, currentText, textInputField.getText().toString()));
            }
            contexts.setSelection(0);
          }

          @Override
          public void onNothingSelected(AdapterView<?> arg0) {}
        });

    // cancel
    Button cancel = (Button) findViewById(R.id.cancel);
    cancel.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            finish();
          }
        });

    // add
    Button addBtn = (Button) findViewById(R.id.addTask);
    if (m_backup != null) {
      addBtn.setText(R.string.update);
    }
    addBtn.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            // strip line breaks
            final String input =
                textInputField.getText().toString().replaceAll("\\r\\n|\\r|\\n", " ");

            TodoApplication app = (TodoApplication) getApplication();
            DropboxAPI api = app.getAPI();
            new AsyncTask<Object, Void, Boolean>() {
              protected void onPreExecute() {
                m_ProgressDialog =
                    ProgressDialog.show(AddTask.this, getTitle(), "Please wait...", true);
              }

              @Override
              protected Boolean doInBackground(Object... params) {
                try {
                  DropboxAPI api = (DropboxAPI) params[0];
                  Task task = (Task) params[1];
                  String input = (String) params[2];
                  TodoApplication m_app = (TodoApplication) params[3];
                  if (api != null) {
                    if (task != null) {
                      task.update(input);
                      return m_app.m_util.updateTask(task);
                    } else {
                      return m_app.m_util.addTask(input);
                    }
                  }
                } catch (Exception e) {
                  Log.e(TAG, "input: " + input + " - " + e.getMessage());
                }
                return false;
              }

              protected void onPostExecute(Boolean result) {
                if (result) {
                  String res =
                      m_backup != null
                          ? getString(R.string.updated_task)
                          : getString(R.string.added_task);
                  Util.showToastLong(AddTask.this, res);
                  finish();
                } else {
                  String res =
                      m_backup != null
                          ? getString(R.string.update_task_failed)
                          : getString(R.string.add_task_failed);
                  Util.showToastLong(AddTask.this, res);
                }
              }
            }.execute(api, m_backup, input, m_app);
          }
        });
  }
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle icicle) {

    boolean abort = false;

    try {
      // handle java.lang.NoClassDefFoundError
      super.onCreate(icicle);
    } catch (Throwable t) {
      ACRA.getErrorReporter().handleSilentException(t);
      IntentsHelper.getInstance().setActivity(this);
      IntentsHelper.getInstance().showInfoToast("Sorry. Your device is currently unsupported :(");
      abort = true;
    }

    if (!abort) {
      final Intent intent = getIntent();
      final String action = intent.getAction();
      // If the intent is a request to create a shortcut, we'll do that and exit
      if (Intent.ACTION_CREATE_SHORTCUT.equals(action)) {
        IntentsHelper.getInstance().setActivity(this);
        IntentsHelper.getInstance().setupShortcut();
        abort = true;
      } else {
        long lastStartupTime =
            ConfigurationManager.getInstance().getLong(ConfigurationManager.LAST_STARTING_DATE);
        LoggerUtils.debug(
            "Last startup time is: "
                + DateTimeUtils.getDefaultDateTimeString(
                    lastStartupTime, ConfigurationManager.getInstance().getCurrentLocale()));
        ConfigurationManager.getInstance()
            .putLong(ConfigurationManager.LAST_STARTING_DATE, System.currentTimeMillis());

        Intent mapActivity;
        if (OsUtil.isHoneycombOrHigher()) {
          if (OsUtil.isGoogleMapActivityInstalled()
              && OsUtil.hasSystemSharedLibraryInstalled(this, "com.google.android.maps")) {
            mapActivity = new Intent(this, GMSClient2MainActivity.class);
          } else {
            ConfigurationManager.getInstance()
                .putInteger(ConfigurationManager.MAP_PROVIDER, ConfigurationManager.OSM_MAPS);
            mapActivity = new Intent(this, GMSClient2OSMMainActivity.class);
          }
        } else {
          if (OsUtil.isGoogleMapActivityInstalled()
              && OsUtil.hasSystemSharedLibraryInstalled(this, "com.google.android.maps")) {
            mapActivity = new Intent(this, GMSClientMainActivity.class);
          } else {
            ConfigurationManager.getInstance()
                .putInteger(ConfigurationManager.MAP_PROVIDER, ConfigurationManager.OSM_MAPS);
            mapActivity = new Intent(this, GMSClientOSMMainActivity.class);
          }
        }
        startActivity(mapActivity);
      }
    }

    if (abort) {
      finish();
    }
  }
Esempio n. 11
0
  @Override
  public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.act_hostlist);

    this.setTitle(
        String.format(
            "%s: %s",
            getResources().getText(R.string.app_name),
            getResources().getText(R.string.title_hosts_list)));

    // check for eula agreement
    this.prefs = PreferenceManager.getDefaultSharedPreferences(this);

    boolean agreed = prefs.getBoolean(PreferenceConstants.EULA, false);
    if (!agreed) {
      this.startActivityForResult(new Intent(this, WizardActivity.class), REQUEST_EULA);
    }

    this.makingShortcut =
        Intent.ACTION_CREATE_SHORTCUT.equals(getIntent().getAction())
            || Intent.ACTION_PICK.equals(getIntent().getAction());

    // connect with hosts database and populate list
    this.hostdb = new HostDatabase(this);
    ListView list = this.getListView();

    this.sortedByColor = prefs.getBoolean(PreferenceConstants.SORT_BY_COLOR, false);

    // this.list.setSelector(R.drawable.highlight_disabled_pressed);

    list.setOnItemClickListener(
        new OnItemClickListener() {

          public synchronized void onItemClick(
              AdapterView<?> parent, View view, int position, long id) {

            // launch off to console details
            HostBean host = (HostBean) parent.getAdapter().getItem(position);
            Uri uri = host.getUri();

            Intent contents = new Intent(Intent.ACTION_VIEW, uri);
            contents.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

            if (makingShortcut) {
              // create shortcut if requested
              ShortcutIconResource icon =
                  Intent.ShortcutIconResource.fromContext(HostListActivity.this, R.drawable.icon);

              Intent intent = new Intent();
              intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, contents);
              intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, host.getNickname());
              intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);

              setResult(RESULT_OK, intent);
              finish();

            } else {
              // otherwise just launch activity to show this host
              HostListActivity.this.startActivity(contents);
            }
          }
        });

    this.registerForContextMenu(list);

    quickconnect = (TextView) this.findViewById(R.id.front_quickconnect);
    quickconnect.setVisibility(makingShortcut ? View.GONE : View.VISIBLE);
    quickconnect.setOnKeyListener(
        new OnKeyListener() {

          public boolean onKey(View v, int keyCode, KeyEvent event) {

            if (event.getAction() == KeyEvent.ACTION_UP) return false;
            if (keyCode != KeyEvent.KEYCODE_ENTER) return false;

            return startConsoleActivity();
          }
        });

    transportSpinner = (Spinner) findViewById(R.id.transport_selection);
    transportSpinner.setVisibility(makingShortcut ? View.GONE : View.VISIBLE);
    ArrayAdapter<String> transportSelection =
        new ArrayAdapter<String>(
            this, android.R.layout.simple_spinner_item, TransportFactory.getTransportNames());
    transportSelection.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    transportSpinner.setOnItemSelectedListener(
        new AdapterView.OnItemSelectedListener() {
          public void onItemSelected(AdapterView<?> arg0, View view, int position, long id) {
            String formatHint =
                TransportFactory.getFormatHint(
                    (String) transportSpinner.getSelectedItem(), HostListActivity.this);

            quickconnect.setHint(formatHint);
            quickconnect.setError(null);
            quickconnect.requestFocus();
          }

          public void onNothingSelected(AdapterView<?> arg0) {}
        });
    transportSpinner.setAdapter(transportSelection);

    this.inflater = LayoutInflater.from(this);
  }
Esempio n. 12
0
  @Override
  protected void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);

    Cursor selection = mDbHelper.fetchBoard(id);
    startManagingCursor(selection);
    final String boardName =
        selection.getString(selection.getColumnIndexOrThrow(MenuDbAdapter.KEY_TITLE));
    int boardLocal = selection.getInt(selection.getColumnIndexOrThrow(MenuDbAdapter.KEY_LOCAL));
    File boardDir = new File(mSbDir, boardName);

    if (Intent.ACTION_CREATE_SHORTCUT.equals(mAction)) {

      Intent shortcutIntent = new Intent(Intent.ACTION_MAIN);
      shortcutIntent.setClassName(this, this.getClass().getName());
      shortcutIntent.putExtra(EXTRA_LAUNCH_BAORD_KEY, boardName);
      shortcutIntent.putExtra(EXTRA_HIDE_SOUNDBOARDMENU, true);
      shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

      Intent intent = new Intent();
      intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
      intent.putExtra(
          Intent.EXTRA_SHORTCUT_NAME,
          selection.getString(selection.getColumnIndexOrThrow(MenuDbAdapter.KEY_TITLE)));

      File icon = new File(mSbDir, boardName + "/icon.png");
      if (icon.exists()) {
        Bitmap bitmap = IconUtils.decodeIcon(super.mContext, icon);
        intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, IconUtils.resizeIcon(this, bitmap, (40 / 12)));
      } else {
        Parcelable iconResource =
            Intent.ShortcutIconResource.fromContext(this, R.drawable.board_icon);
        intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource);
      }

      setResult(RESULT_OK, intent);

      finish();
      return;

    } else if (mMoveBoard > -1) {

      Cursor moveFrom = mDbHelper.fetchBoard(mMoveBoard);
      startManagingCursor(moveFrom);

      String moveSourceTitle =
          moveFrom.getString(moveFrom.getColumnIndexOrThrow(MenuDbAdapter.KEY_TITLE));
      int moveSourceLocal =
          moveFrom.getInt(moveFrom.getColumnIndexOrThrow(MenuDbAdapter.KEY_LOCAL));

      mDbHelper.updateBoard((int) id, moveSourceTitle, moveSourceLocal);
      mDbHelper.updateBoard(mMoveBoard, boardName, boardLocal);

      mMoveBoard = -1;

      initializeBoardUpdateThread();

    } else {

      try {
        boolean boardFileFound = false;
        for (File boardDirContent : boardDir.listFiles()) {
          if (boardDirContent.getName().equals("graphicalBoard")) {
            Intent i = new Intent(this, BoardEditor.class);
            i.putExtra(MenuDbAdapter.KEY_TITLE, boardName);
            startActivity(i);
            boardFileFound = true;
            break;
          }
        }
        if (!boardFileFound) {
          Intent i = new Intent(this, BoardEditor.class);
          i.putExtra(MenuDbAdapter.KEY_TITLE, boardName);
          startActivity(i);
        }
      } catch (NullPointerException npe) {
        Log.e(SoundboardMenu.TAG, "Unable to list boards", npe);
      }
    }
  }
Esempio n. 13
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    GlobalSettings.init(this);
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    super.mContext = (Context) this;
    ImageDrawing.registerCache(super.mContext);

    Log.i(TAG, "Boarder storage directory is " + mSbDir.getAbsolutePath());

    super.onCreate(savedInstanceState);

    mIntent = getIntent();
    mAction = mIntent.getAction();

    if (Intent.ACTION_CREATE_SHORTCUT.equals(mAction)) {
      setTitle("Select shortcut target:");
    } else {
      setTitle("Soundboard Menu");
    }

    String launchExtra = mIntent.getStringExtra(EXTRA_LAUNCH_BAORD_KEY);
    if (launchExtra != null) {
      try {
        Intent i = null;

        for (File boardDirContent : new File(mSbDir, launchExtra).listFiles()) {
          if (boardDirContent.getName().equals("graphicalBoard")) {
            i = new Intent(this, BoardEditor.class);
            break;
          }
        }
        i.putExtra(MenuDbAdapter.KEY_TITLE, launchExtra);
        startActivity(i);
      } catch (NullPointerException e) {
        mIntent = new Intent();
        Log.e(SoundboardMenu.TAG, "Board not found", e);
        Toast.makeText(this, "Board not found", Toast.LENGTH_LONG).show();
      }
    }

    this.setVolumeControlStream(AudioManager.STREAM_MUSIC);

    mFunctionSounds.add(mPauseSoundFilePath);
    mFunctionSounds.add(mTopBlackBarSoundFilePath);
    mFunctionSounds.add(mBottomBlackBarSoundFilePath);
    mFunctionSounds.add(mLeftBlackBarSoundFilePath);
    mFunctionSounds.add(mRightBlackBarSoundFilePath);

    mDbHelper = new MenuDbAdapter(this);
    mDbHelper.open();

    mGlobalVariableDbHelper = new GlobalVariablesDbAdapter(this);
    mGlobalVariableDbHelper.open();

    loadGlobalSettings();

    if (!mSbDir.exists()) {
      mSbDir.mkdirs();
    }

    refreshMenu();
    LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
    View layout =
        inflater.inflate(
            R.layout.soundboard_menu_list, (ViewGroup) findViewById(R.id.soundboard_menu_root));
    Button enableNotificationButton = (Button) layout.findViewById(R.id.enableNotificationButton);
    Button disableNotificationButton = (Button) layout.findViewById(R.id.disableNotificationButton);

    enableNotificationButton.setOnClickListener(
        new OnClickListener() {
          public void onClick(View v) {
            updateNotification(SoundboardMenu.this, "Soundboard Menu", null);
          }
        });

    disableNotificationButton.setOnClickListener(
        new OnClickListener() {
          public void onClick(View v) {
            final NotificationManager notificationManager =
                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
            notificationManager.cancel(SoundboardMenu.TAG, mNotificationId);
          }
        });

    setContentView(layout);
    registerForContextMenu(getListView());

    firstStartIntroduction();
  }
  public ContactsRequest resolveIntent(Intent intent) {
    ContactsRequest request = new ContactsRequest();

    String action = intent.getAction();

    Log.i(TAG, "Called with action: " + action);

    if (UI.LIST_DEFAULT.equals(action)) {
      request.setActionCode(ContactsRequest.ACTION_DEFAULT);
    } else if (UI.LIST_ALL_CONTACTS_ACTION.equals(action)) {
      request.setActionCode(ContactsRequest.ACTION_ALL_CONTACTS);
    } else if (UI.LIST_CONTACTS_WITH_PHONES_ACTION.equals(action)) {
      request.setActionCode(ContactsRequest.ACTION_CONTACTS_WITH_PHONES);
    } else if (UI.LIST_STARRED_ACTION.equals(action)) {
      request.setActionCode(ContactsRequest.ACTION_STARRED);
    } else if (UI.LIST_FREQUENT_ACTION.equals(action)) {
      request.setActionCode(ContactsRequest.ACTION_FREQUENT);
    } else if (UI.LIST_STREQUENT_ACTION.equals(action)) {
      request.setActionCode(ContactsRequest.ACTION_STREQUENT);
    } else if (UI.LIST_GROUP_ACTION.equals(action)) {
      request.setActionCode(ContactsRequest.ACTION_GROUP);
      // We no longer support UI.GROUP_NAME_EXTRA_KEY
    } else if (Intent.ACTION_PICK.equals(action)) {
      final String resolvedType = intent.resolveType(mContext);
      if (Contacts.CONTENT_TYPE.equals(resolvedType)) {
        request.setActionCode(ContactsRequest.ACTION_PICK_CONTACT);
      } else if (People.CONTENT_TYPE.equals(resolvedType)) {
        request.setActionCode(ContactsRequest.ACTION_PICK_CONTACT);
        request.setLegacyCompatibilityMode(true);
      } else if (Phone.CONTENT_TYPE.equals(resolvedType)) {
        request.setActionCode(ContactsRequest.ACTION_PICK_PHONE);
      } else if (Phones.CONTENT_TYPE.equals(resolvedType)) {
        request.setActionCode(ContactsRequest.ACTION_PICK_PHONE);
        request.setLegacyCompatibilityMode(true);
      } else if (StructuredPostal.CONTENT_TYPE.equals(resolvedType)) {
        request.setActionCode(ContactsRequest.ACTION_PICK_POSTAL);
      } else if (ContactMethods.CONTENT_POSTAL_TYPE.equals(resolvedType)) {
        request.setActionCode(ContactsRequest.ACTION_PICK_POSTAL);
        request.setLegacyCompatibilityMode(true);
      } else if (Email.CONTENT_TYPE.equals(resolvedType)) {
        request.setActionCode(ContactsRequest.ACTION_PICK_EMAIL);
      }
    } else if (Intent.ACTION_CREATE_SHORTCUT.equals(action)) {
      String component = intent.getComponent().getClassName();
      if (component.equals("alias.DialShortcut")) {
        request.setActionCode(ContactsRequest.ACTION_CREATE_SHORTCUT_CALL);
      } else if (component.equals("alias.MessageShortcut")) {
        request.setActionCode(ContactsRequest.ACTION_CREATE_SHORTCUT_SMS);
      } else {
        request.setActionCode(ContactsRequest.ACTION_CREATE_SHORTCUT_CONTACT);
      }
    } else if (Intent.ACTION_GET_CONTENT.equals(action)) {
      String type = intent.getType();
      if (Contacts.CONTENT_ITEM_TYPE.equals(type)) {
        request.setActionCode(ContactsRequest.ACTION_PICK_OR_CREATE_CONTACT);
      } else if (Phone.CONTENT_ITEM_TYPE.equals(type)) {
        request.setActionCode(ContactsRequest.ACTION_PICK_PHONE);
      } else if (Phones.CONTENT_ITEM_TYPE.equals(type)) {
        request.setActionCode(ContactsRequest.ACTION_PICK_PHONE);
        request.setLegacyCompatibilityMode(true);
      } else if (StructuredPostal.CONTENT_ITEM_TYPE.equals(type)) {
        request.setActionCode(ContactsRequest.ACTION_PICK_POSTAL);
      } else if (ContactMethods.CONTENT_POSTAL_ITEM_TYPE.equals(type)) {
        request.setActionCode(ContactsRequest.ACTION_PICK_POSTAL);
        request.setLegacyCompatibilityMode(true);
      } else if (People.CONTENT_ITEM_TYPE.equals(type)) {
        request.setActionCode(ContactsRequest.ACTION_PICK_OR_CREATE_CONTACT);
        request.setLegacyCompatibilityMode(true);
      }
    } else if (Intent.ACTION_INSERT_OR_EDIT.equals(action)) {
      request.setActionCode(ContactsRequest.ACTION_INSERT_OR_EDIT_CONTACT);
    } else if (Intent.ACTION_SEARCH.equals(action)) {
      // See if the suggestion was clicked with a search action key (call button)
      if ("call".equals(intent.getStringExtra(SearchManager.ACTION_MSG))) {
        String query = intent.getStringExtra(SearchManager.QUERY);
        if (!TextUtils.isEmpty(query)) {
          Intent newIntent =
              new Intent(Intent.ACTION_CALL_PRIVILEGED, Uri.fromParts("tel", query, null));
          request.setRedirectIntent(newIntent);
        }
      } else {
        request.setQueryString(intent.getStringExtra(SearchManager.QUERY));
        request.setSearchMode(true);
      }
    } else if (Intent.ACTION_VIEW.equals(action)) {
      final String resolvedType = intent.resolveType(mContext);
      if (ContactsContract.Contacts.CONTENT_TYPE.equals(resolvedType)
          || android.provider.Contacts.People.CONTENT_TYPE.equals(resolvedType)) {
        request.setActionCode(ContactsRequest.ACTION_ALL_CONTACTS);
      } else {
        request.setActionCode(ContactsRequest.ACTION_VIEW_CONTACT);
        request.setContactUri(intent.getData());
        intent.setAction(Intent.ACTION_DEFAULT);
        intent.setData(null);
      }
    } else if (UI.FILTER_CONTACTS_ACTION.equals(action)) {
      // When we get a FILTER_CONTACTS_ACTION, it represents search in the context
      // of some other action. Let's retrieve the original action to provide proper
      // context for the search queries.
      request.setActionCode(ContactsRequest.ACTION_DEFAULT);
      Bundle extras = intent.getExtras();
      if (extras != null) {
        request.setQueryString(extras.getString(UI.FILTER_TEXT_EXTRA_KEY));

        ContactsRequest originalRequest =
            (ContactsRequest) extras.get(ContactsSearchManager.ORIGINAL_REQUEST_KEY);
        if (originalRequest != null) {
          request.copyFrom(originalRequest);
        }
      }

      request.setSearchMode(true);

      // Since this is the filter activity it receives all intents
      // dispatched from the SearchManager for security reasons
      // so we need to re-dispatch from here to the intended target.
    } else if (Intents.SEARCH_SUGGESTION_CLICKED.equals(action)) {
      Uri data = intent.getData();
      // See if the suggestion was clicked with a search action key (call button)
      if ("call".equals(intent.getStringExtra(SearchManager.ACTION_MSG))) {
        Intent newIntent = new Intent(mContext, CallContactActivity.class);
        newIntent.setData(data);
        request.setRedirectIntent(newIntent);
      } else {
        request.setActionCode(ContactsRequest.ACTION_VIEW_CONTACT);
        request.setContactUri(data);
        intent.setAction(Intent.ACTION_DEFAULT);
        intent.setData(null);
      }
    } else if (Intents.SEARCH_SUGGESTION_DIAL_NUMBER_CLICKED.equals(action)) {
      request.setRedirectIntent(new Intent(Intent.ACTION_CALL_PRIVILEGED, intent.getData()));
    } else if (Intents.SEARCH_SUGGESTION_CREATE_CONTACT_CLICKED.equals(action)) {
      // TODO actually support this in EditContactActivity.
      String number = intent.getData().getSchemeSpecificPart();
      Intent newIntent = new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI);
      newIntent.putExtra(Intents.Insert.PHONE, number);
      request.setRedirectIntent(newIntent);
    }
    // Allow the title to be set to a custom String using an extra on the intent
    String title = intent.getStringExtra(UI.TITLE_EXTRA_KEY);
    if (title != null) {
      request.setActivityTitle(title);
    }
    return request;
  }