示例#1
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_search);
    databaseManager = new DatabaseManager(this);

    recyclerView = (RecyclerView) findViewById(R.id.results);
    StaggeredGridLayoutManager layoutManager;
    if (getResources().getBoolean(R.bool.landscape)) {
      layoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
    } else {
      layoutManager = new StaggeredGridLayoutManager(1, StaggeredGridLayoutManager.VERTICAL);
    }
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    adapter = new SearchListAdapter();
    recyclerView.setAdapter(adapter);

    searchBar = (EditText) findViewById(R.id.search_bar);
    searchBar.addTextChangedListener(this);

    searchContainer = findViewById(R.id.search_container);
    parent = findViewById(R.id.parent);

    if (SharedPrefs.getInstance().transcriptSearchEnabled()) {
      searchBar.setHint(R.string.hint_search_transcript);
    } else {
      searchBar.setHint(R.string.hint_search);
    }

    home = findViewById(R.id.home);
    clear = findViewById(R.id.clear);
    clear.setOnClickListener(this);
    home.setOnClickListener(this);

    if (SharedPrefs.getInstance().isNightModeEnabled()) {
      searchContainer.setBackgroundColor(getResources().getColor(R.color.primary_night));
      parent.setBackgroundColor(getResources().getColor(R.color.primary_light_night));
      if (BlipUtils.isLollopopUp()) {
        getWindow().setStatusBarColor(getResources().getColor(R.color.primary_dark_night));
      }
    }
  }
示例#2
0
      @Override
      public void onClick(View v) {
        final int position = getAdapterPosition();
        switch (v.getId()) {
          case R.id.open_in_browser:
            Intent intent =
                new Intent(
                    Intent.ACTION_VIEW,
                    Uri.parse("http://xkcd.com/" + comics.get(position).getNum()));
            startActivity(intent);
            break;
          case R.id.transcript:
            String content = comics.get(position).getTranscript();
            if (content.equals("")) {
              content = getResources().getString(R.string.message_no_transcript);
            }
            final String speakingContent = content;
            new MaterialDialog.Builder(SearchActivity.this)
                .title(R.string.title_dialog_transcript)
                .content(content)
                .negativeText(R.string.negative_text_dialog)
                .neutralText(R.string.neutral_text_dialog_speak)
                .autoDismiss(false)
                .callback(
                    new MaterialDialog.ButtonCallback() {
                      @Override
                      public void onNegative(MaterialDialog dialog) {
                        super.onNegative(dialog);
                        dialog.dismiss();
                      }

                      @Override
                      public void onNeutral(MaterialDialog dialog) {
                        super.onNeutral(dialog);
                        SpeechSynthesizer.getInstance().convertToSpeechFlush(speakingContent);
                      }
                    })
                .dismissListener(
                    new DialogInterface.OnDismissListener() {
                      @Override
                      public void onDismiss(DialogInterface dialog) {
                        SpeechSynthesizer.getInstance().stopSpeaking();
                      }
                    })
                .show();
            break;
          case R.id.img_container:
            ImageActivity.launch(SearchActivity.this, img, comics.get(position).getNum());
            break;
          case R.id.favourite:
            boolean fav = comics.get(position).isFavourite();
            comics.get(position).setFavourite(!fav);
            databaseManager.setFavourite(comics.get(position).getNum(), !fav);
            if (fav) {
              if (SharedPrefs.getInstance().isNightModeEnabled()) {
                favourite.setColorFilter(getResources().getColor(android.R.color.white));
              } else {
                favourite.setColorFilter(getResources().getColor(R.color.icons_dark));
              }
            } else {
              // make fav
              favourite.setColorFilter(getResources().getColor(R.color.accent));
            }
            break;
          case R.id.help:
            Intent explainIntent =
                new Intent(
                    Intent.ACTION_VIEW,
                    Uri.parse(
                        "http://www.explainxkcd.com/wiki/index.php/"
                            + comics.get(position).getNum()));
            startActivity(explainIntent);
            break;
          case R.id.share:
            Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
            shareIntent.setType("text/plain");
            if (BlipUtils.isLollopopUp()) {
              shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
            } else {
              shareIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
            }
            shareIntent.putExtra(Intent.EXTRA_SUBJECT, comics.get(position).getTitle());
            shareIntent.putExtra(Intent.EXTRA_TEXT, comics.get(position).getImg());
            startActivity(
                Intent.createChooser(
                    shareIntent, getResources().getString(R.string.tip_share_image_url)));
            break;
          case R.id.alt:
            alt.setText(comics.get(position).getAlt());
            alt.setClickable(false);
            break;
        }
      }