Esempio n. 1
1
  private void setupHistoryRow(View view, History history, User user) {
    final AsyncImageView pictureView = (AsyncImageView) view.findViewById(R.id.picture);
    {
      if (user.containsNonNullValue(USER_PICTURE)) {
        String pictureUrl = user.getPictureUrl(USER_PICTURE, RemoteModel.PICTURE_THUMB);
        pictureView.setUrl(pictureUrl);
      } else {
        pictureView.setUrl(null);
      }
      pictureView.setVisibility(View.VISIBLE);
    }

    final AsyncImageView commentPictureView =
        (AsyncImageView) view.findViewById(R.id.comment_picture);
    commentPictureView.setVisibility(View.GONE);

    final TextView nameView = (TextView) view.findViewById(R.id.title);
    {
      nameView.setText(
          getHistoryComment(
              (AstridActivity) fragment.getActivity(), history, user, linkColor, fromView));
      nameView.setTextColor(grayColor);
    }

    final TextView date = (TextView) view.findViewById(R.id.date);
    {
      CharSequence dateString =
          DateUtils.getRelativeTimeSpanString(
              history.getValue(History.CREATED_AT),
              DateUtilities.now(),
              DateUtils.MINUTE_IN_MILLIS,
              DateUtils.FORMAT_ABBREV_RELATIVE);
      date.setText(dateString);
    }
  }
Esempio n. 2
0
  public static void openBrowse(Uri uri, Fragment fragment) {
    Intent intent =
        new Intent(
            Intent
                .ACTION_GET_CONTENT); // TODO implement preference that allows to use
                                      // ACTION_OPEN_DOCUMENT
    intent.addCategory(Intent.CATEGORY_OPENABLE);

    intent.setDataAndType(uri, "*/*");

    try {
      fragment.startActivityForResult(
          intent, ProtectedFragmentActivity.IMPORT_FILENAME_REQUESTCODE);
    } catch (ActivityNotFoundException e) {
      // No compatible file manager was found.
      Toast.makeText(fragment.getActivity(), R.string.no_filemanager_installed, Toast.LENGTH_SHORT)
          .show();
    } catch (SecurityException ex) {
      Toast.makeText(
              fragment.getActivity(),
              String.format(
                  "Sorry, this destination does not accept %s request. Please select a different one.",
                  intent.getAction()),
              Toast.LENGTH_SHORT)
          .show();
    }
  }
Esempio n. 3
0
  @SuppressLint("SetJavaScriptEnabled")
  protected void loginWebview(final OsmOAuth.AuthType type) {
    final WebView webview = new InputWebView(mFragment.getActivity());
    webview.getSettings().setJavaScriptEnabled(true);
    final AlertDialog dialog =
        new AlertDialog.Builder(mFragment.getActivity()).setView(webview).create();

    ThreadPool.getWorker()
        .execute(
            new Runnable() {
              @Override
              public void run() {
                final String[] auth =
                    (type == OsmOAuth.AuthType.FACEBOOK)
                        ? OsmOAuth.nativeGetFacebookAuthUrl()
                        : OsmOAuth.nativeGetGoogleAuthUrl();

                UiThread.run(
                    new Runnable() {
                      @Override
                      public void run() {
                        if (mFragment.isAdded()) loadWebviewAuth(dialog, webview, auth, type);
                      }
                    });
              }
            });

    dialog.show();
  }
  protected void onPostExecute(Bitmap bitmap) {
    final String finalMessage = errorMessage;

    if (fragment == null || fragment.getActivity() == null) {
      return;
    }

    if (isCancelled()) {
      bitmap = null;
    }
    final Bitmap finalBitmap = bitmap;

    // Set image and hide progress animation
    fragment
        .getActivity()
        .runOnUiThread(
            new Runnable() {
              public void run() {
                ProgressBar progress =
                    (ProgressBar) fragment.getActivity().findViewById(R.id.progressBar);
                progress.setVisibility(View.GONE);
                if (finalBitmap != null) {
                  image.setVisibility(View.VISIBLE);
                  image.setImageBitmap(finalBitmap);
                } else if (errorMessage != null) {
                  Toast.makeText(context, finalMessage, Toast.LENGTH_LONG).show();
                }
                // otherwise the ad doesn't contain any photo
              }
            });
  }
Esempio n. 5
0
  public EditNoteActivity(Fragment fragment, View parent, long t) {
    super(fragment.getActivity());
    DependencyInjectionService.getInstance().inject(this);

    imageCache = AsyncImageView.getImageCache();
    this.fragment = fragment;

    this.activity = (AstridActivity) fragment.getActivity();

    this.resources = fragment.getResources();
    TypedValue tv = new TypedValue();
    fragment.getActivity().getTheme().resolveAttribute(R.attr.asTextColor, tv, false);
    color = tv.data;

    fragment.getActivity().getTheme().resolveAttribute(R.attr.asDueDateColor, tv, false);
    grayColor = tv.data;

    linkColor = UpdateAdapter.getLinkColor(fragment);

    cameraButton = getDefaultCameraButton();

    setOrientation(VERTICAL);

    commentsBar = parent.findViewById(R.id.updatesFooter);

    loadViewForTaskID(t);
  }
Esempio n. 6
0
  protected void processAuth(@Size(2) String[] auth, OsmOAuth.AuthType type, String username) {
    if (auth == null) {
      if (mFragment.isAdded()) {
        new AlertDialog.Builder(mFragment.getActivity())
            .setTitle(R.string.editor_login_error_dialog)
            .setPositiveButton(android.R.string.ok, null)
            .show();

        Statistics.INSTANCE.trackEvent(
            Statistics.EventName.EDITOR_AUTH_REQUEST_RESULT,
            Statistics.params()
                .add(Statistics.EventParam.IS_SUCCESS, false)
                .add(Statistics.EventParam.TYPE, type.name));
      }
      return;
    }

    OsmOAuth.setAuthorization(auth[0], auth[1], username);
    if (mFragment.isAdded()) Utils.navigateToParent(mFragment.getActivity());
    Statistics.INSTANCE.trackEvent(
        Statistics.EventName.EDITOR_AUTH_REQUEST_RESULT,
        Statistics.params()
            .add(Statistics.EventParam.IS_SUCCESS, true)
            .add(Statistics.EventParam.TYPE, type.name));
  }
 // simple convenience function for when a fragment wants to log a URL
 // don't need to worry about making sure it only happens once, because Fragments manage their own
 // state
 // in a way that activities do not.
 public static void track(Fragment fragment, String url) {
   if (fragment.isAdded()) {
     GoogleAnalyticsTracker tracker = start(fragment.getActivity());
     page(fragment.getActivity(), tracker, url);
     stop(tracker);
   }
 }
 /**
  * @param fragment the fragment from where the keyboard will be removed
  * @brief methods for hiding the soft keyboard by forced
  */
 public static void hideSoftKeyboard(Fragment fragment) {
   if (fragment.getActivity().getCurrentFocus() != null) {
     InputMethodManager inputMethodManager =
         (InputMethodManager)
             fragment.getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
     inputMethodManager.hideSoftInputFromWindow(
         fragment.getActivity().getCurrentFocus().getWindowToken(), 0);
   }
 }
  @Override
  public void onAttach() {
    Intent intent = new Intent(fragment.getActivity(), PlayMusicService.class);

    fragment.getActivity().bindService(intent, mPlayMusicConnection, Service.BIND_AUTO_CREATE);

    registerMusicReceiver(); // ×¢²á·þÎñ

    // ÅжÏÊDz»ÊÇÒѾ­²¥·ÅÁË,²¥·ÅÁ˾ÍÄÃÐÅÏ¢³öÀ´
  }
Esempio n. 10
0
  protected void onPreExecute() {
    TextView title = (TextView) fragment.getActivity().findViewById(R.id.textTitle);
    TextView description = (TextView) fragment.getActivity().findViewById(R.id.textDescription);

    image = (ImageView) fragment.getActivity().findViewById(R.id.imageImage);
    image.setVisibility(View.INVISIBLE);
    title.setText(ad.getTitle());
    description.setText(ad.getBody());
    fragment.getActivity().setTitle(ad.getTitle());
  }
Esempio n. 11
0
 public static void startThisActivity(
     Fragment fragment, @NonNull String orderid, @NonNull String sellid, ShopCarInfo shopCarInfo) {
   if (CommonUtil.isLoginAndToLogin(fragment.getActivity(), false)) {
     Intent intent = new Intent(fragment.getActivity(), AddCommonActivity.class);
     intent.putExtra("oid", orderid);
     intent.putExtra("sid", sellid);
     Bundle bundle = new Bundle();
     bundle.putSerializable("goods", shopCarInfo);
     intent.putExtras(bundle);
     fragment.startActivityForResult(intent, 1);
   }
 }
Esempio n. 12
0
  /**
   * Constructor
   *
   * @param activity
   * @param resource layout resource to inflate
   * @param c database cursor
   * @param autoRequery whether cursor is automatically re-queried on changes
   * @param onCompletedTaskListener goal listener. can be null
   */
  public UpdateAdapter(
      Fragment fragment, int resource, Cursor c, boolean autoRequery, String fromView) {
    super(fragment.getActivity(), c, autoRequery);
    DependencyInjectionService.getInstance().inject(this);

    linkColor = getLinkColor(fragment);

    inflater =
        (LayoutInflater) fragment.getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    imageCache = ImageDiskCache.getInstance();
    this.fromView = fromView;

    this.resource = resource;
    this.fragment = fragment;
  }
  @Override
  public void onResume() {

    super.onResume();
    frag = getVisibleFragment();
    globalContext = frag.getActivity();
  }
Esempio n. 14
0
 public ShowAdTask(Fragment _fragment, Ad _ad) {
   api = NolotiroAPI.getInstance();
   context = _fragment.getActivity();
   fragment = _fragment;
   ad = _ad;
   Log.i(TAG, "ad=" + ad);
 }
Esempio n. 15
0
 public static void showSimpleBackForResult(
     Fragment fragment, int requestCode, SimpleBackPage page, Bundle args) {
   Intent intent = new Intent(fragment.getActivity(), SimpleBackActivity.class);
   intent.putExtra(SimpleBackActivity.BUNDLE_KEY_PAGE, page.getValue());
   intent.putExtra(SimpleBackActivity.BUNDLE_KEY_ARGS, args);
   fragment.startActivityForResult(intent, requestCode);
 }
Esempio n. 16
0
 public static void openCameraFrom(Fragment fragment, @NonNull File imageFile) {
   Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
   if (takePictureIntent.resolveActivity(fragment.getActivity().getPackageManager()) != null) {
     takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(imageFile));
     fragment.startActivityForResult(takePictureIntent, CAMERA_REQUEST_CODE);
   }
 }
Esempio n. 17
0
 public DMConversationAdapter(Fragment fragment, List<DMBean> bean, ListView listView) {
   this.bean = bean;
   this.commander = TimeLineBitmapDownloader.getInstance();
   this.inflater = fragment.getActivity().getLayoutInflater();
   this.listView = listView;
   this.fragment = fragment;
 }
Esempio n. 18
0
  public ScoresAdapter(
      Context context,
      Cursor cursor,
      int flags,
      Fragment fragment,
      ScoresAdapterScrollHandler scrollHandler) {
    super(context, cursor, flags);
    mScrollHandler = scrollHandler;
    //        Log.v(LOG_TAG, "ScoresAdapter, " + "context = [" + context + "], cursor = [" + cursor
    // + "], flags = [" + flags + "]");

    // create requestBuilder for svg-glide-usage as described here:
    // https://github.com/bumptech/glide/tree/v3.6.0/samples/svg/src/main/java/com/bumptech/svgsample/app
    // uses androidsvg: http://mvnrepository.com/artifact/com.caverock/androidsvg/1.2.1
    requestBuilder =
        Glide.with(fragment)
            .using(
                Glide.buildStreamModelLoader(Uri.class, fragment.getActivity()), InputStream.class)
            .from(Uri.class)
            .as(SVG.class)
            .transcode(new SvgDrawableTranscoder(), PictureDrawable.class)
            .sourceEncoder(new StreamEncoder())
            .cacheDecoder(new FileToStreamDecoder<>(new SvgDecoder()))
            .decoder(new SvgDecoder())
            .placeholder(R.drawable.image_loading)
            .error(R.drawable.no_icon)
            .animate(android.R.anim.fade_in)
            .listener(new SvgSoftwareLayerSetter<Uri>());
  }
  @Override
  public void onDetach() {

    unRegisterMusicReceiver();

    fragment.getActivity().unbindService(mPlayMusicConnection);
  }
Esempio n. 20
0
 public static void openChooser(Fragment fragment) {
   try {
     Intent intent = createChooserIntent(fragment.getActivity());
     fragment.startActivityForResult(intent, REQ_SOURCE_CHOOSER);
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
Esempio n. 21
0
 public a(Fragment fragment, android.view.View.OnClickListener onclicklistener, int j) {
   b = fragment;
   c = fragment.getActivity();
   h = onclicklistener;
   f = j;
   g = c.getResources().getDisplayMetrics().widthPixels;
   e = g / j;
 }
Esempio n. 22
0
 @Override
 public void onBindViewHolder(ViewHolder holder, int position) {
   if (paginas.get(position).getUrl() != null) {
     Picasso.with(fragment.getActivity())
         .load(paginas.get(position).getUrl())
         .into(holder.imgPagina);
   }
 }
  protected void registerMusicReceiver() {
    // ¼àÌý²¥·Å½ø¶È

    progressReceiver = new SongProgressReceiver();
    fragment.getActivity().registerReceiver(progressReceiver, progressFilter);
    // ¼àÌý¸è´Ê
    lrcReceiver = new SongLrcReceiver();

    fragment.getActivity().registerReceiver(lrcReceiver, songFilter);
    // ¼àÌý×ܳ¤¶È
    durationReceiver = new SongDurationReceiver();
    fragment.getActivity().registerReceiver(durationReceiver, songDurationFilter);
    // ¼àÌýÍ£Ö¹
    songStopReceiver = new SongStopReceiver();
    fragment.getActivity().registerReceiver(songStopReceiver, songStopFilter);
    // ¼àÌýÔÝÍ£µÄ
    pauseReceiver = new SongPauseReceiver();
    fragment.getActivity().registerReceiver(pauseReceiver, songPauseFilter);
    // ²¥·ÅÍê³É

    completeReceiver = new SongCompleteReceiver();

    fragment.getActivity().registerReceiver(completeReceiver, songCompleteFilter);

    restartReceiver = new SongRestartReceiver();

    fragment.getActivity().registerReceiver(restartReceiver, songRestartFilter);
  }
Esempio n. 24
0
  public GetAddress_WebService(Fragment mFragment, Location myLoaction) {
    TAG = "LoginWebService";
    Log.d(MODULE, TAG);

    this.mFragment = mFragment;
    this.mActivity = mFragment.getActivity();
    this.myLoaction = myLoaction;
    mCallBack = (Address_Received_Listener) mFragment;
  }
Esempio n. 25
0
  @Override
  public void onBindViewHolder(ViewHolder holder, int position) {

    ArtistData artistData = artistDataList.get(position);
    holder.artistTitle.setText(artistData.getPost_title());
    Picasso.with(context.getActivity())
        .load(artistData.getFeatured_image())
        .into(holder.artistImage);
  }
Esempio n. 26
0
  private void setupUserActivityRow(View view, UserActivity activity, User user) {
    final AsyncImageView pictureView = (AsyncImageView) view.findViewById(R.id.picture);
    {
      if (user.containsNonNullValue(USER_PICTURE)) {
        String pictureUrl = user.getPictureUrl(USER_PICTURE, RemoteModel.PICTURE_THUMB);
        pictureView.setUrl(pictureUrl);
      } else {
        pictureView.setUrl(null);
      }
      pictureView.setVisibility(View.VISIBLE);
    }

    final AsyncImageView commentPictureView =
        (AsyncImageView) view.findViewById(R.id.comment_picture);
    {
      String pictureThumb =
          activity.getPictureUrl(UserActivity.PICTURE, RemoteModel.PICTURE_MEDIUM);
      String pictureFull = activity.getPictureUrl(UserActivity.PICTURE, RemoteModel.PICTURE_LARGE);
      Bitmap updateBitmap = null;
      if (TextUtils.isEmpty(pictureThumb))
        updateBitmap = activity.getPictureBitmap(UserActivity.PICTURE);
      setupImagePopupForCommentView(
          view,
          commentPictureView,
          pictureThumb,
          pictureFull,
          updateBitmap,
          activity.getValue(UserActivity.MESSAGE),
          fragment,
          imageCache);
    }

    // name
    final TextView nameView = (TextView) view.findViewById(R.id.title);
    {
      nameView.setText(
          getUpdateComment(
              (AstridActivity) fragment.getActivity(), activity, user, linkColor, fromView));
      nameView.setMovementMethod(new LinkMovementMethod());
      nameView.setTextColor(color);
    }

    // date
    final TextView date = (TextView) view.findViewById(R.id.date);
    {
      CharSequence dateString =
          DateUtils.getRelativeTimeSpanString(
              activity.getValue(UserActivity.CREATED_AT),
              DateUtilities.now(),
              DateUtils.MINUTE_IN_MILLIS,
              DateUtils.FORMAT_ABBREV_RELATIVE);
      date.setText(dateString);
    }
  }
Esempio n. 27
0
  public LoadingAndRetryManager(
      Object activityOrFragmentOrView, OnLoadingAndRetryListener listener) {
    if (listener == null) listener = DEFAULT_LISTENER;

    ViewGroup contentParent = null;
    Context context;
    if (activityOrFragmentOrView instanceof Activity) {
      Activity activity = (Activity) activityOrFragmentOrView;
      context = activity;
      contentParent = (ViewGroup) activity.findViewById(android.R.id.content);
    } else if (activityOrFragmentOrView instanceof Fragment) {
      Fragment fragment = (Fragment) activityOrFragmentOrView;
      context = fragment.getActivity();
      contentParent = (ViewGroup) (fragment.getView().getParent());
    } else if (activityOrFragmentOrView instanceof View) {
      View view = (View) activityOrFragmentOrView;
      contentParent = (ViewGroup) (view.getParent());
      context = view.getContext();
    } else {
      throw new IllegalArgumentException(
          "the argument's type must be Fragment or Activity: init(context)");
    }
    int childCount = contentParent.getChildCount();
    // get contentParent
    int index = 0;
    View oldContent;
    if (activityOrFragmentOrView instanceof View) {
      oldContent = (View) activityOrFragmentOrView;
      for (int i = 0; i < childCount; i++) {
        if (contentParent.getChildAt(i) == oldContent) {
          index = i;
          break;
        }
      }
    } else {
      oldContent = contentParent.getChildAt(0);
    }
    contentParent.removeView(oldContent);
    // setup content layout
    LoadingAndRetryLayout loadingAndRetryLayout = new LoadingAndRetryLayout(context);

    ViewGroup.LayoutParams lp = oldContent.getLayoutParams();
    contentParent.addView(loadingAndRetryLayout, index, lp);
    loadingAndRetryLayout.setContentView(oldContent);
    // setup loading,retry,empty layout
    setupLoadingLayout(listener, loadingAndRetryLayout);
    setupRetryLayout(listener, loadingAndRetryLayout);
    setupEmptyLayout(listener, loadingAndRetryLayout);
    // callback
    listener.setRetryEvent(loadingAndRetryLayout.getRetryView());
    listener.setLoadingEvent(loadingAndRetryLayout.getLoadingView());
    listener.setEmptyEvent(loadingAndRetryLayout.getEmptyView());
    mLoadingAndRetryLayout = loadingAndRetryLayout;
  }
Esempio n. 28
0
  public static boolean checkPermission(Fragment fragment, String permission, int code) {
    if (ContextCompat.checkSelfPermission(fragment.getActivity(), permission)
        != PackageManager.PERMISSION_GRANTED) {

      if (fragment.shouldShowRequestPermissionRationale(permission)) {
        fragment.requestPermissions(new String[] {permission}, code);
      } else {
        fragment.requestPermissions(new String[] {permission}, code);
      }
      return false;
    }
    return true;
  }
Esempio n. 29
0
  /**
   * Constructor
   *
   * @param activity
   * @param resource layout resource to inflate
   * @param c database cursor
   * @param autoRequery whether cursor is automatically re-queried on changes
   * @param onCompletedTaskListener goal listener. can be null
   */
  public UpdateAdapter(
      Fragment fragment, int resource, Cursor c, boolean autoRequery, String fromView) {
    super(fragment.getActivity(), c, autoRequery);
    DependencyInjectionService.getInstance().inject(this);

    linkColor = getLinkColor(fragment);

    inflater =
        (LayoutInflater) fragment.getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    imageCache = AsyncImageView.getImageCache();
    this.fromView = fromView;

    this.resource = resource;
    this.fragment = fragment;
    this.self = getSelfUser();

    TypedValue tv = new TypedValue();
    fragment.getActivity().getTheme().resolveAttribute(R.attr.asTextColor, tv, false);
    color = tv.data;

    fragment.getActivity().getTheme().resolveAttribute(R.attr.asDueDateColor, tv, false);
    grayColor = tv.data;
  }
 public MobileBindings(
     Fragment fragment,
     String activityId,
     String activityToLoad,
     String sitesToLoad,
     ContentValues newSite,
     String themesToLoad) {
   this.ctx = fragment.getActivity();
   this.fragment = fragment;
   this.activityId = activityId;
   this.activityToLoad = activityToLoad;
   this.sitesToLoad = sitesToLoad;
   this.newSite = newSite;
   this.themesToLoad = themesToLoad;
 }