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

The following are Jave code examples for showing how to use getContext() of the android.view.View class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: mobile-app-dev-book   File: JournalFragment.java   Source Code and License Vote up 7 votes
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_journal_list, container, false);
    Bundle data = getArguments();
    int cellLayout = data.getInt(ARG_LAYOUT);
    // Set the adapter
    if (view instanceof RecyclerView) {
        FirebaseDatabase dbRef = FirebaseDatabase.getInstance();
        FirebaseAuth auth = FirebaseAuth.getInstance();
        FirebaseUser user = auth.getCurrentUser();
        DatabaseReference userRef = dbRef.getReference(user.getUid());
        userRef.addChildEventListener (chEvListener);
        userRef.addValueEventListener(valEvListener);
        Context context = view.getContext();
        RecyclerView recyclerView = (RecyclerView) view;
        recyclerView.setLayoutManager(new LinearLayoutManager(context));
        adapter = new JournalAdapter(selectedTrips, cellLayout, mListener);
        recyclerView.setAdapter(adapter);
    }
    return view;
}
 
Example 2
Project: shrinker   File: ItemListActivity.java   Source Code and License Vote up 7 votes
@Override
public void onClick(View view) {
    DummyContent.DummyItem item = (DummyContent.DummyItem) view.getTag();
    if (mTwoPane) {
        Bundle arguments = new Bundle();
        arguments.putString(ItemDetailFragment.ARG_ITEM_ID, item.id);
        ItemDetailFragment fragment = new ItemDetailFragment();
        fragment.setArguments(arguments);
        mParentActivity.getSupportFragmentManager().beginTransaction()
                .replace(R.id.item_detail_container, fragment)
                .commit();
    } else {
        Context context = view.getContext();
        Intent intent = new Intent(context, ItemDetailActivity.class);
        intent.putExtra(ItemDetailFragment.ARG_ITEM_ID, item.id);

        context.startActivity(intent);
    }
}
 
Example 3
Project: Selector   File: DStateLayout.java   Source Code and License Vote up 7 votes
public static DStateLayout wrap(View view) {
  if (view == null) {
    throw new RuntimeException("content view can not be null");
  }
  ViewGroup parent = (ViewGroup) view.getParent();
  if (parent == null) {
    throw new RuntimeException("parent view can not be null");
  }
  ViewGroup.LayoutParams lp = view.getLayoutParams();
  int index = parent.indexOfChild(view);
  parent.removeView(view);

  DStateLayout layout = new DStateLayout(view.getContext());
  parent.addView(layout, index, lp);
  layout.addView(view);
  layout.setContentView(view);
  return layout;
}
 
Example 4
Project: MinimalismJotter   File: BasePopupWindowForListView.java   Source Code and License Vote up 6 votes
public BasePopupWindowForListView(View contentView, int width, int height,
                                  boolean focusable, List<T> mDatas, Object... params) {
    super(contentView, width, height, focusable);
    this.mContentView = contentView;
    context = contentView.getContext();
    if (mDatas != null)
        this.mDatas = mDatas;

    if (params != null && params.length > 0) {
        beforeInitWeNeedSomeParams(params);
    }

    setBackgroundDrawable(new BitmapDrawable());
    setTouchable(true);
    setOutsideTouchable(true);
    setTouchInterceptor(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {
                dismiss();
                return true;
            }
            return false;
        }
    });
    initViews();
    initEvents();
    init();
}
 
Example 5
Project: javaide   File: LogLineViewHolder.java   Source Code and License Vote up 6 votes
@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 6
Project: home-assistant-Android   File: SwitchViewHolder.java   Source Code and License Vote up 6 votes
@Override
public void onClick(View v) {
    BaseActivity activity = (BaseActivity) v.getContext();
    activity.send(new ToggleRequest(entity, stateSwitch.isChecked()), (success, result) -> activity.runOnUiThread(() -> {
        if (success) {
            entity.state = HassUtils.getOnState(entity, stateSwitch.isChecked());
            updateColor();
        } else {
            stateSwitch.toggle();
        }
    }));
}
 
Example 7
Project: UIKit-ViewBlock   File: ContextViewBlock.java   Source Code and License Vote up 6 votes
protected ContextViewBlock(View blockingView) {
    Preconditions.checkNotNull(blockingView);
    this.mBlockingView = blockingView;
    mBlockingViewId = blockingView.getId();
    this.mContext = blockingView.getContext();
    this.mActivity = (Activity) this.mContext;
    onAttachToActivity(mActivity);
}
 
Example 8
Project: Android-skin-support   File: SkinCompatViewInflater.java   Source Code and License Vote up 6 votes
public final View createView(View parent, final String name, @NonNull Context context,
                             @NonNull AttributeSet attrs, boolean inheritContext,
                             boolean readAndroidTheme, boolean readAppTheme) {
    // We can emulate Lollipop's android:theme attribute propagating down the view hierarchy
    // by using the parent's context
    if (inheritContext && parent != null) {
        context = parent.getContext();
    }
    if (readAndroidTheme || readAppTheme) {
        // We then apply the theme on the context, if specified
        context = themifyContext(context, attrs, readAndroidTheme, readAppTheme);
    }

    View view = createViewFromHackInflater(context, name, attrs);

    // We need to 'inject' our tint aware Views in place of the standard framework versions
    if (view == null) {
        view = createViewFromFV(context, name, attrs);
    }

    if (view == null) {
        view = createViewFromInflater(context, name, attrs);
    }

    if (view == null) {
        view = createViewFromTag(context, name, attrs);
    }

    if (view != null) {
        // If we have created a view, check it's android:onClick
        checkOnClickListener(view, attrs);
    }

    return view;
}
 
Example 9
Project: permitlog-android   File: HomeFragment.java   Source Code and License Vote up 6 votes
@Override public void onClick(View view) {
    // Check if the user is signed in:
    boolean isSignedIn = FirebaseHelper.signInIfNeeded((MainActivity)getActivity());
    // Don't do anything if the user isn't signed in:
    if (!isSignedIn) return;

    // Close the plus button menu
    FloatingActionMenu floatingMenu = (FloatingActionMenu) rootView.findViewById(R.id.menu);
    floatingMenu.close(false);

    // Open the activity (which masquerades as a dialog)
    Intent intent = new Intent(view.getContext(), DriverDialog.class);
    intent.putExtra("driverId", "");
    startActivity(intent);
}
 
Example 10
Project: BestBlog   File: ColumnFragment.java   Source Code and License Vote up 6 votes
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_column_list, container, false);

    // Set the adapter
    if (view instanceof RecyclerView) {
        Context context = view.getContext();
        RecyclerView recyclerView = (RecyclerView) view;
        recyclerView.setLayoutManager(new LinearLayoutManager(context));
        recyclerView.setAdapter(new ColumnRecyclerViewAdapter(mList, mListener));
    }
    return view;
}
 
Example 11
Project: revolution-irc   File: MaterialColorSetting.java   Source Code and License Vote up 6 votes
@Override
public void onClick(View v) {
    MaterialColorSetting entry = getEntry();
    MaterialColorPickerDialog dialog = new MaterialColorPickerDialog(v.getContext());
    dialog.setTitle(entry.mName);
    dialog.setColorPickListener(entry::setSelectedColor);
    dialog.show();
}
 
Example 12
Project: QiangHongBao   File: BlurTask.java   Source Code and License Vote up 6 votes
public BlurTask(View target, BlurFactor factor, Callback callback) {
  this.res = target.getResources();
  this.factor = factor;
  this.callback = callback;
  this.contextWeakRef = new WeakReference<>(target.getContext());

  target.setDrawingCacheEnabled(true);
  target.destroyDrawingCache();
  target.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_LOW);
  bitmap = target.getDrawingCache();
}
 
Example 13
Project: boohee_v5.6   File: KPSwitchConflictUtil.java   Source Code and License Vote up 6 votes
public static void showPanel(View panelLayout) {
    Activity activity = (Activity) panelLayout.getContext();
    panelLayout.setVisibility(0);
    if (activity.getCurrentFocus() != null) {
        KeyboardUtil.hideKeyboard(activity.getCurrentFocus());
    }
}
 
Example 14
Project: andswipeframework   File: RecylerViewWithRestoreFragment.java   Source Code and License Vote up 6 votes
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_recyclerview_with_restore, container, false);

    // Set the adapter
    if (view instanceof RecyclerView) {
        Context context = view.getContext();
        RecyclerView recyclerView = (RecyclerView) view;
        recyclerView.setLayoutManager(new LinearLayoutManager(context));
        recyclerView.setAdapter(new MyItemRecyclerViewAdapter(DummyContent.ITEMS, mListener));
    }
    return view;
}
 
Example 15
Project: Samantha   File: InfoBeanViewHolder.java   Source Code and License Vote up 6 votes
InfoBeanViewHolder(View itemView) {
    super(itemView);
    ButterKnife.bind(this, itemView);
    context = itemView.getContext();
    setupRvMetaInfo();
    tvOriginText.setVisibility(View.GONE);
    mShortAnimationDuration = context.getResources().getInteger(
            android.R.integer.config_shortAnimTime);
}
 
Example 16
Project: inventum   File: TvAdapter.java   Source Code and License Vote up 6 votes
public TvHolder(View itemView) {
    super(itemView);
    ButterKnife.bind(this, itemView);
    mContext = itemView.getContext();
}
 
Example 17
Project: ModuleFrame   File: LeakUtil.java   Source Code and License Vote up 6 votes
/**
 * 解决部分机型InputMethodManager导致的内存泄漏
 *
 * @param destContext 上下文
 */
public static void fixInputMethodManagerLeak(Context destContext) {
    if (destContext == null) {
        return;
    }

    InputMethodManager inputMethodManager = (InputMethodManager) destContext.getSystemService(Context.INPUT_METHOD_SERVICE);
    if (inputMethodManager == null) {
        return;
    }

    String [] viewArray = new String[]{"mCurRootView", "mServedView", "mNextServedView"};
    Field filed;
    Object filedObject;

    for (String view:viewArray) {
        try{
            filed = inputMethodManager.getClass().getDeclaredField(view);
            if (!filed.isAccessible()) {
                filed.setAccessible(true);
            }
            filedObject = filed.get(inputMethodManager);
            if (filedObject != null && filedObject instanceof View) {
                View fileView = (View) filedObject;
                if (fileView.getContext() == destContext) { // 被InputMethodManager持有引用的context是想要目标销毁的
                    filed.set(inputMethodManager, null); // 置空,破坏掉path to gc节点
                } else {
                    break;// 不是想要目标销毁的,即为又进了另一层界面了,不要处理,避免影响原逻辑,也就不用继续for循环了
                }
            }
        }catch(Throwable t){
            t.printStackTrace();
        }
    }
}
 
Example 18
Project: MyNotes   File: MainFragment.java   Source Code and License Vote up 5 votes
public void openNoteDetail(View v, Note note, CardView noteCard){
    Intent it = new Intent(v.getContext(), NoteDetailActivity.class);
    it.putExtra(Note.NOTE_PARCE, note);
    openActivity(it, noteCard);
}
 
Example 19
Project: OracionesCatolicas   File: JornadaFragment.java   Source Code and License Vote up 5 votes
private void configureRecyclerView(View view) {
    recyclerView = (RecyclerView) view.findViewById(R.id.view_jornadas);
    recyclerView.setHasFixedSize(true);
    RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(view.getContext());
    recyclerView.setLayoutManager(layoutManager);
}
 
Example 20
Project: GerenciadorDeConvidados   File: AllInvitedFragment.java   Source Code and License Vote up 5 votes
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    // 'Infla' a view para retornar para o container
    View rootView = inflater.inflate(R.layout.fragment_all_invited, container, false);
    this.mContext = rootView.getContext();

    // Acesso a dados
    this.mGuestBusiness = new GuestBusiness(rootView.getContext());

    // Obtém elementos
    this.mViewHolder.textAllGuests = (TextView) rootView.findViewById(R.id.text_total_guests);
    this.mViewHolder.textAllPresent = (TextView) rootView.findViewById(R.id.text_total_present);
    this.mViewHolder.textAllAbsent = (TextView) rootView.findViewById(R.id.text_total_absent);

    // 1 - Obter a recyclerview
    this.mViewHolder.mRecyclerView = (RecyclerView) rootView.findViewById(R.id.recycler_all_invited);

    // Ações na listagem
    this.mOnGuestListInteractionListener = new OnGuestListInteractionListener() {
        @Override
        public void onListClick(int guestId) {
            Bundle bundle = new Bundle();
            bundle.putInt(GuestConstants.BundleConstants.GUEST_ID, guestId);

            Intent intent = new Intent(getContext(), GuestFormActivity.class);
            intent.putExtras(bundle);
            startActivity(intent);
        }

        @Override
        public void onDeleteClick(int guestId) {

            // Remove convidados do banco de dados
            mGuestBusiness.remove(guestId);

            // Notifica que convidado foi salvo
            Toast.makeText(mContext, R.string.removido_com_sucesso, Toast.LENGTH_LONG).show();

            // Atualiza listagem
            loadGuests();

            // Carrega quantidade de convidados
            loadDashboard();
        }
    };

    // Carrega convidados
    this.mListGuest = this.mGuestBusiness.getInvited();

    // 2 - Definir adapter passando listagme de convidados e listener
    this.mGuestListAdapter = new GuestListAdapter(this.mListGuest, mOnGuestListInteractionListener);
    this.mViewHolder.mRecyclerView.setAdapter(this.mGuestListAdapter);

    // 3 - Definir um layout
    this.mViewHolder.mRecyclerView.setLayoutManager(new LinearLayoutManager(this.mContext));

    // Retorna view
    return rootView;
}