コード例 #1
0
 @Override
 public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   this.preferences = new DilbertPreferences(getActivity());
   this.zoomLevel = preferences.getDefaultZoomLevel();
   setHasOptionsMenu(true);
 }
コード例 #2
0
 @Override
 protected void onCreate(Bundle savedInstance) {
   DilbertPreferences preferences = new DilbertPreferences(this);
   if (preferences.isForceLandscape())
     setRequestedOrientation(preferences.getLandscapeOrientation());
   setTheme(preferences.isDarkLayoutEnabled() ? R.style.AppThemeDark : R.style.AppThemeLight);
   super.onCreate(savedInstance);
   setContentView(R.layout.activity_dilbert_fragments);
   if (getSupportActionBar() != null) {
     getSupportActionBar().setDisplayHomeAsUpEnabled(true);
   }
   boolean isOfflineMode = getIntent().getBooleanExtra(INTENT_OFFLINE, false);
   viewPager = (ViewPager) findViewById(R.id.view_pager);
   adapter =
       new DilbertFavoritedFragmentAdapter(
           getSupportFragmentManager(),
           isOfflineMode ? preferences.getCachedDates() : preferences.getFavoritedItems());
   if (adapter.getCount() == 0) {
     Toast.makeText(this, R.string.toast_no_favorites, Toast.LENGTH_LONG).show();
     finish();
   }
   viewPager.addOnPageChangeListener(pageChangedListener);
   viewPager.setAdapter(adapter);
   viewPager.setCurrentItem(adapter.getCount());
   if (preferences.isToolbarsHidden()) ActionBarUtility.toggleActionBar(this, viewPager);
 }
コード例 #3
0
 private void refreshAction() {
   Glide.get(getContext()).clearMemory();
   preferences.removeCache(getDateFromArguments());
   if (this.loadTask == null || this.loadTask.getStatus() != Status.PENDING) {
     this.loadTask =
         new GetStripUrl(getStripURIlListener, preferences, getDateFromArguments(), progress);
   }
   this.loadTask.execute();
 }
コード例 #4
0
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
   switch (item.getItemId()) {
     case MENU_FAVORITE:
       preferences.toggleIsFavorited(getDateFromArguments());
       modifyFavoriteItem(item);
       return true;
     case MENU_ZOOM:
       applyZoomLevel();
       return true;
     case MENU_SHARE:
       shareCurrentStrip();
       return true;
     case MENU_REFRESH:
       refreshAction();
       return true;
     case MENU_OPEN_AT:
       preferences.saveCurrentDate(getDateFromArguments());
       getActivity().finish();
       return true;
     case MENU_OPEN_IN_BROWSER:
       try {
         startActivity(
             new Intent(
                 Intent.ACTION_VIEW, Uri.parse(preferences.getCachedUrl(getDateFromArguments()))));
       } catch (Throwable t) {
         Log.e("DilbertFragment", "Cannot ACTION_VIEW url", t);
       }
       return true;
     case MENU_SAVE:
       preferences.downloadImageViaManager(
           getActivity(),
           preferences.getCachedUrl(getDateFromArguments()),
           getDateFromArguments());
       return true;
   }
   return super.onOptionsItemSelected(item);
 }
コード例 #5
0
  private void shareCurrentStrip() {
    String url = preferences.getCachedUrl(getDateFromArguments());
    if (url == null) return;
    Glide.with(DilbertFragment.this)
        .load(url)
        .asBitmap()
        .into(
            new SimpleTarget<Bitmap>() {
              @Override
              public void onResourceReady(Bitmap b, GlideAnimation<? super Bitmap> glideAnimation) {
                try {
                  String date = getDateFromArguments().toString(DilbertPreferences.DATE_FORMATTER);
                  Intent i = new Intent(Intent.ACTION_SEND);
                  i.setType("image/jpeg");
                  i.putExtra(Intent.EXTRA_SUBJECT, "Dilbert " + date + " #simpledilbert");
                  if (preferences.isSharingImage()) {
                    i.putExtra(Intent.EXTRA_TEXT, "Dilbert " + date + " #simpledilbert");
                    if (b != null) {
                      File tmp =
                          File.createTempFile(
                              "dilbert_", ".jpg", getActivity().getExternalCacheDir());
                      FileOutputStream out = new FileOutputStream(tmp);
                      b.compress(CompressFormat.JPEG, 100, out);
                      out.close();
                      Uri u = Uri.parse("file://" + tmp.getAbsolutePath());
                      i.putExtra(Intent.EXTRA_STREAM, u);
                    }
                  } else {
                    i.putExtra(
                        Intent.EXTRA_TEXT,
                        "Dilbert "
                            + date
                            + " #simpledilbert http://dilbert.com/strips/comic/"
                            + date);
                  }
                  startActivity(Intent.createChooser(i, getString(R.string.share_chooser)));

                } catch (Throwable e) {
                  if (getActivity() != null)
                    Toast.makeText(
                            getActivity(), R.string.loading_exception_error, Toast.LENGTH_LONG)
                        .show();
                }
              }
            });
  }
コード例 #6
0
 @Override
 public View onCreateView(
     LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
   View fragment = inflater.inflate(R.layout.fragment_dilbert, container, false);
   assert fragment != null;
   this.image = (PhotoView) fragment.findViewById(R.id.fragment_imageview);
   this.image.setOnLongClickListener(imageLongClickListener);
   fragment.setOnLongClickListener(imageLongClickListener);
   this.image.setOnPhotoTapListener(photoTapListener);
   this.progress = (ProgressBar) fragment.findViewById(R.id.fragment_progressbar);
   String cachedUrl = preferences.getCachedUrl(getDateFromArguments());
   if (null != cachedUrl) {
     getStripURIlListener.displayImage(cachedUrl);
   } else {
     this.loadTask = new GetStripUrl(getStripURIlListener, preferences, getDateFromArguments());
     this.loadTask.execute();
   }
   return fragment;
 }
コード例 #7
0
 private void modifyFavoriteItem(MenuItem favorite) {
   boolean isFavorite = preferences.isFavorited(getDateFromArguments());
   favorite.setTitle(isFavorite ? R.string.menu_favorite_remove : R.string.menu_favorite_add);
   favorite.setIcon(isFavorite ? R.drawable.ic_menu_favorited : R.drawable.ic_menu_not_favorited);
 }