Java Code Examples for android.view.View#getContext()

The following examples show how to use android.view.View#getContext() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: Bailan   File: ParallaxRecyclerAdapter.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Set the view as header.
 *
 * @param header The inflated header
 * @param view   The RecyclerView to set scroll listeners
 */
public void setParallaxHeader(View header, final RecyclerView view) {
    mRecyclerView = view;
    mHeader = new CustomRelativeWrapper(header.getContext(), mShouldClipView);
    mHeader.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    mHeader.addView(header, new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    view.setOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            if (mHeader != null) {
                translateHeader(mRecyclerView.getLayoutManager().getChildAt(0) == mHeader ?
                        mRecyclerView.computeVerticalScrollOffset() : mHeader.getHeight());

            }
        }
    });
}
 
Example 2
@SuppressWarnings("ConstantConditions,PrivateResource")
public static void showTooltip(@NonNull final View view, @StringRes final int titleResId,
                               int gravity, @Nullable final OnTooltipDismissListener dismissListener) {
    if (view != null && view.getContext() != null) {
        if (!PrefHelper.getBoolean(String.valueOf(titleResId))) {
            new Tooltip.Builder(view)
                    .setText(titleResId)
                    .setTypeface(TypeFaceHelper.getTypeface())
                    .setTextColor(Color.WHITE)
                    .setGravity(gravity)
                    .setPadding(R.dimen.spacing_xs_large)
                    .setBackgroundColor(ContextCompat.getColor(view.getContext(), R.color.primary))
                    .setDismissOnClick(true)
                    .setCancelable(true)
                    .setTextStyle(android.support.v7.appcompat.R.style.TextAppearance_AppCompat_Title_Inverse)
                    .setOnDismissListener(new OnDismissListener() {
                        @Override public void onDismiss() {
                            PrefHelper.set(String.valueOf(titleResId), true);
                            if (dismissListener != null) dismissListener.onDismissed(titleResId);
                        }
                    })
                    .show();
        }
    }
}
 
Example 3
@Override
public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
  super.onViewCreated(view, savedInstanceState);

  // Set the Recycler View adapter
  Context context = view.getContext();
  mRecyclerView.setLayoutManager(new LinearLayoutManager(context));
  mRecyclerView.setAdapter(mEarthquakeAdapter);

  // Setup the Swipe to Refresh view
  mSwipeToRefreshView.setOnRefreshListener(
    new SwipeRefreshLayout.OnRefreshListener() {
      @Override
      public void onRefresh() {
        updateEarthquakes();
      }
    });
}
 
Example 4
@Override
public void onClick(View widget) {
  String url = getURL();
  if (url.startsWith(PREFIX_MAILTO)) {
    try {
      String addr = prepareUrl(url);
      Activity activity = (Activity) widget.getContext();
      DcContext dcContext = DcHelper.getContext(activity);
      DcContact contact = dcContext.getContact(dcContext.createContact(null, addr));
      if (contact.getId()!=0 && dcContext.getChatIdByContactId(contact.getId())!=0) {
        openChat(activity, contact);
      } else {
        new AlertDialog.Builder(activity)
                .setMessage(activity.getString(R.string.ask_start_chat_with, contact.getNameNAddr()))
                .setPositiveButton(android.R.string.ok, (dialog, which) -> {
                  openChat(activity, contact);
                })
                .setNegativeButton(R.string.cancel, null)
                .show();
      }
    }
    catch(Exception e) {
      e.printStackTrace();
    }
  }
  else {
    super.onClick(widget);
  }
}
 
Example 5
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
		Bundle savedInstanceState) {
	View v = inflater.inflate(R.layout.new_welcome_intro, null);
	context = v.getContext();
	
	SharedPreferences settings = context.getSharedPreferences(PREFS_NAME, 0);
	
	nextButton = (Button) v.findViewById(R.id.buttonNewWelcomeNext);
	nextButton.setOnClickListener(this);
	
	checkBarometer();
	
	welcomeNewDescription = (TextView) v.findViewById(R.id.welcome_new_description);
	
	if(!hasBarometer) {
		welcomeNewDescription.setText(getString(R.string.newWelcomeNoBarometerIntro));
	} else {
		welcomeNewDescription.setText(getString(R.string.newWelcomeBarometerIntro));
	}
	
	
	// set default units that are region aware/localized
	Locale current = getResources().getConfiguration().locale;
	if(current.getCountry().equals("US")) {
		// default to 'ft' and 'F'
	      SharedPreferences.Editor editor = settings.edit();
	      editor.putString("distance_units", "Feet (ft)");
	      editor.putString("temperature_units", "Fahrenheit (°F)");
	      editor.commit();
	}
	

	// updateView();
	return v;
}
 
Example 6
private static String getTargetPage(View view) {
    try {
        Context context = view.getContext();
        if (context instanceof Activity) {
            Activity activity = (Activity) context;
            return activity.getClass().getName();
        }
    } catch (Throwable e) {
        InternalAgent.e(e);
    }
    return "";
}
 
Example 7
@Override
public void onClick(View widget) {
    String url = getURL();
    if (url != null && widget.getContext() instanceof WindowControl) {
        WebViewDialogFragment
                .newInstance(url, "")
                .show(
                        ((WindowControl) widget.getContext()).getFragmentUtility().getFragmentManager(),
                        WebViewDialogFragment.TAG
                );
    } else if (url != null) {
        RxBus.get().post(new OpenWebView(url));
    }
}
 
Example 8
@Override
public boolean onLongClick(View v) {
    PopupMenu menu = new PopupMenu(v.getContext(), v);
    menu.getMenu().add(0, CONTEXT_MENU_FILTER_ID, 0, R.string.filter_choice);
    menu.getMenu().add(0, CONTEXT_MENU_COPY_ID, 0, R.string.copy_to_clipboard);
    menu.setOnMenuItemClickListener(LogLineViewHolder.this);
    menu.show();
    return true;
}
 
Example 9
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    EmojiconRecentsManager recents = EmojiconRecentsManager
            .getInstance(view.getContext());

    mAdapter = new EmojiconAdapter(view.getContext(), recents, mUseSystemDefault);
    GridView gridView = (GridView) view.findViewById(R.id.Emoji_GridView);
    gridView.setAdapter(mAdapter);
    gridView.setOnItemClickListener(this);
}
 
Example 10
public LawnAndGardenCardItemView(View view) {
    super(view);
    serviceImage = (ImageView) view.findViewById(R.id.service_image);
    serviceName = (Version1TextView) view.findViewById(R.id.service_name);
    this.context = view.getContext();
    zoneCount = view.findViewById(R.id.zonecount);
    zoneCountText = (Version1TextView) view.findViewById(R.id.water_zone_count);
    timeImage = (ImageView) view.findViewById(R.id.time_image);
}
 
Example 11
/**
 * @param flags Provides additional operating flags.  Set to 0 if there are no additional flags.
 */
public static void showInputMethod(@Nullable final View view, int flags) {
    if (view == null || view.getContext() == null) {
        return;
    }

    final InputMethodManager imm = (InputMethodManager) view.getContext()
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    if (imm == null) {
        return;
    }
    imm.showSoftInput(view, flags);
}
 
Example 12
Source Project: GoogleVR   File: VrVideoAdapter.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onClick(View v) {
	VideoItem item= (VideoItem) v.getTag();
	Intent intent=new Intent(v.getContext(),VideoDetailActivity.class);
	//需要传递的数据:
	intent.putExtra("title",item.title);
	intent.putExtra("img",item.img);
	intent.putExtra("text",item.text);
	intent.putExtra("play",item.play);
	v.getContext().startActivity(intent);
}
 
Example 13
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
						 Bundle savedInstanceState) {
	// Inflate the layout for this fragment
	View view= inflater.inflate(R.layout.frament_content, container, false);
	recyclerView=(RecyclerView)view.findViewById(R.id.frg_content_recyclerview);
	LinearLayoutManager linearLayoutManager = new LinearLayoutManager(view.getContext());
	recyclerView.setLayoutManager(linearLayoutManager);
	recyclerView.setHasFixedSize(true);
	recyclerView.setAdapter(searchAdapter);
	return view;
}
 
Example 14
public LargeOnTouchListener(final View view) {
    gestureDetector = new GestureDetector(view.getContext(), new GestureDetector.SimpleOnGestureListener() {
        @Override
        public boolean onSingleTapUp(MotionEvent e) {
            Utility.playClickSound(view);
            getActivity().onBackPressed();
            return true;
        }
    });
}
 
Example 15
Source Project: guideshow   File: ExploreByTouchHelper.java    License: MIT License 5 votes vote down vote up
/**
 * Factory method to create a new {@link ExploreByTouchHelper}.
 *
 * @param forView View whose logical children are exposed by this helper.
 */
public ExploreByTouchHelper(View forView) {
    if (forView == null) {
        throw new IllegalArgumentException("View may not be null");
    }

    mView = forView;
    final Context context = forView.getContext();
    mManager = (AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE);
}
 
Example 16
public void cancel(View view){
    Intent intentHome = new Intent(view.getContext(), MainActivity.class);
    intentHome.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    view.getContext().startActivity(intentHome);
}
 
Example 17
@SuppressLint("ClickableViewAccessibility")
public static PictureInPictureGestureHelper applyTo(@NonNull View child) {
  TouchInterceptingFrameLayout  parent          = (TouchInterceptingFrameLayout) child.getParent();
  PictureInPictureGestureHelper helper          = new PictureInPictureGestureHelper(parent, child);
  GestureDetectorCompat         gestureDetector = new GestureDetectorCompat(child.getContext(), helper);

  parent.setOnInterceptTouchEventListener((event) -> {
    if (helper.velocityTracker == null) {
      helper.velocityTracker = VelocityTracker.obtain();
    }

    helper.velocityTracker.addMovement(event);

    return false;
  });

  parent.setOnTouchListener((v, event) -> {
    if (helper.velocityTracker != null) {
      helper.velocityTracker.recycle();
      helper.velocityTracker = null;
    }

    return false;
  });

  child.setOnTouchListener((v, event) -> {
    boolean handled = gestureDetector.onTouchEvent(event);

    if (event.getActionMasked() == MotionEvent.ACTION_UP || event.getActionMasked() == MotionEvent.ACTION_CANCEL) {
      if (!handled) {
        handled = helper.onGestureFinished(event);
      }

      if (helper.velocityTracker != null) {
        helper.velocityTracker.recycle();
        helper.velocityTracker = null;
      }
    }

    return handled;
  });

  return helper;
}
 
Example 18
Source Project: timecat   File: DragDropHelper.java    License: Apache License 2.0 4 votes vote down vote up
public void startDrag(View v) {
    isInit = true;
    mDragView = new DragView(v.getContext(), v);
    mDragView.setImageBitmap(getViewBitmap(v));
    mDragView.dragStart();
}
 
Example 19
Source Project: FimiX8-RE   File: X8GimbalItemController.java    License: MIT License 4 votes vote down vote up
public X8GimbalItemController(View rootView) {
    super(rootView);
    this.mContext = rootView.getContext();
}
 
Example 20
Source Project: android_9.0.0_r45   File: PopupWindow.java    License: Apache License 2.0 3 votes vote down vote up
/**
 * <p>Create a new popup window which can display the <tt>contentView</tt>.
 * The dimension of the window must be passed to this constructor.</p>
 *
 * <p>The popup does not provide any background. This should be handled
 * by the content view.</p>
 *
 * @param contentView the popup's content
 * @param width the popup's width
 * @param height the popup's height
 * @param focusable true if the popup can be focused, false otherwise
 */
public PopupWindow(View contentView, int width, int height, boolean focusable) {
    if (contentView != null) {
        mContext = contentView.getContext();
        mWindowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
    }

    setContentView(contentView);
    setWidth(width);
    setHeight(height);
    setFocusable(focusable);
}