Java Code Examples for android.support.v7.app.AppCompatActivity

The following are top voted examples for showing how to use android.support.v7.app.AppCompatActivity. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: Android-Demo_ImageCroper   File: MainActivity.java   View source code 8 votes vote down vote up
@Override
@SuppressLint("NewApi")
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == CropImage.PICK_IMAGE_CHOOSER_REQUEST_CODE && resultCode == AppCompatActivity.RESULT_OK) {
        Uri imageUri = CropImage.getPickImageResultUri(this, data);

        // For API >= 23 we need to check specifically that we have permissions to read external storage,
        // but we don't know if we need to for the URI so the simplest is to try open the stream and see if we get error.
        boolean requirePermissions = false;
        if (CropImage.isReadExternalStoragePermissionsRequired(this, imageUri)) {

            // request permissions and handle the result in onRequestPermissionsResult()
            requirePermissions = true;
            mCropImageUri = imageUri;
            requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, CropImage.PICK_IMAGE_PERMISSIONS_REQUEST_CODE);
        } else {

            mCurrentFragment.setImageUri(imageUri);
        }
    }
}
 
Example 2
Project: MovieApp   File: PeopleDetailFragment.java   View source code 7 votes vote down vote up
private void init(View view) {
    unbinder = ButterKnife.bind(this, view);
    activity = (AppCompatActivity) getActivity();
    activity.setSupportActionBar(toolbar);

    animation = AnimationUtils.loadAnimation(activity, R.anim.fade_in);
    animation.setDuration(1000);

    ActionBar actionBar = activity.getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setDisplayShowTitleEnabled(false);
    }

    tryAgainBtn.setOnClickListener(v -> presenter.onPersonDetailRequested(personId));
}
 
Example 3
Project: BLE-Indoor-Positioning   File: BeaconViewFragment.java   View source code 6 votes vote down vote up
public BeaconViewFragment() {
    deviceLocationListener = createDeviceLocationListener();
    beaconUpdateListener = createBeaconUpdateListener();
    closestGateChangeListener = new ClosestGateChangeListener() {
        @Override
        public void onClosestGateDistanceChanged(GateGroup gateGroup, Gate gate, float distance) {
            Log.v("Gate", "Closest gate distance changed to: " + String.format("%.2f", distance) + " meters");
            ((AppCompatActivity) getActivity()).getSupportActionBar().setTitle("Gate " + gate.getIndex() + " - " + String.format("%.2f", distance) + "m");
        }

        @Override
        public void onClosestGateChanged(GateGroup gateGroup, Gate gate, float distance) {
            Log.d("Gate", "Closest gate changed to: " + gate);
        }

        @Override
        public void onClosestGateGroupChanged(GateGroup gateGroup, Gate gate, float distance) {
            Log.d("Gate", "Closest gate group changed to: " + gateGroup);
        }
    };
}
 
Example 4
Project: quickblox-android   File: ImagePickHelperFragment.java   View source code 6 votes vote down vote up
@Override
public void onAttach(Context context) {
    super.onAttach(context);
    Fragment fragment = ((AppCompatActivity) context).getSupportFragmentManager()
            .findFragmentByTag(getArguments().getString(ARG_PARENT_FRAGMENT));
    if (fragment != null) {
        if (fragment instanceof OnImagePickedListener) {
            listener = (OnImagePickedListener) fragment;
        }
    } else {
        if (context instanceof OnImagePickedListener) {
            listener = (OnImagePickedListener) context;
        }
    }

    if (listener == null) {
        throw new IllegalStateException("Either activity or fragment should implement OnImagePickedListener");
    }
}
 
Example 5
Project: mobile-store   File: SettingsView.java   View source code 6 votes vote down vote up
@Override
protected void onDetachedFromWindow() {
    super.onDetachedFromWindow();

    AppCompatActivity activity = (AppCompatActivity) getContext();
    if (activity == null) {
        throw new IllegalArgumentException("Cannot add a SettingsView to activities which are not an AppCompatActivity");
    }

    Fragment existingFragment = activity.getSupportFragmentManager().findFragmentByTag("preferences-fragment");
    if (existingFragment == null) {
        return;
    }

    if (currentTransaction == null) {
        currentTransaction = activity.getSupportFragmentManager().beginTransaction();
    }
    currentTransaction.remove(existingFragment);
    currentTransaction.commitAllowingStateLoss();
    currentTransaction = null;
    activity.getSupportFragmentManager().executePendingTransactions();
}
 
Example 6
Project: weex-3d-map   File: ScreenUtil.java   View source code 6 votes vote down vote up
private static int getStatusBarHeight(AppCompatActivity activity) {
    Class<?> c;
    Object obj;
    Field field;
    int x;
    int statusBarHeight = 0;
    try {
        c = Class.forName("com.android.internal.R$dimen");
        obj = c.newInstance();
        field = c.getField("status_bar_height");
        x = Integer.parseInt(field.get(obj).toString());
        statusBarHeight = activity.getResources().getDimensionPixelSize(x);
    } catch (Exception e1) {
        e1.printStackTrace();
    }
    return statusBarHeight;
}
 
Example 7
Project: MovieApp   File: GenreFragment.java   View source code 6 votes vote down vote up
private void init(View view) {
    unbinder = ButterKnife.bind(this, view);

    activity = (AppCompatActivity) getActivity();

    activity.setSupportActionBar(toolbar);
    ActionBar actionBar = activity.getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setDisplayShowTitleEnabled(true);
        actionBar.setTitle(title);
    }

    LinearLayoutManager layoutManager
            = new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false);
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.addItemDecoration(new DividerItemDecoration(activity, layoutManager.getOrientation()));
    recyclerView.setHasFixedSize(true);
    recyclerView.setMotionEventSplittingEnabled(false);
    recyclerView.setNestedScrollingEnabled(false);
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    recyclerView.setAdapter(genreAdapter);
}
 
Example 8
Project: qvod   File: TitleLayout.java   View source code 6 votes vote down vote up
public TitleLayout(Context context, AttributeSet attrs) {
    super(context, attrs);
    LayoutInflater.from(context).inflate(R.layout.include_title_layout, this);
    //
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    //
    ((AppCompatActivity) getContext()).setSupportActionBar(toolbar);
    ActionBar actionBar = ((AppCompatActivity) getContext()).getSupportActionBar();
    if (actionBar != null) {
        //是否显示默认Title
        actionBar.setDisplayShowTitleEnabled(true);
        //是否显示返回键
        actionBar.setDisplayHomeAsUpEnabled(true);
        //监听返回键
        toolbar.setNavigationOnClickListener(view -> ((AppCompatActivity) getContext()).onBackPressed());
    }
}
 
Example 9
Project: GSoC-Info-Android   File: OrgAdapter.java   View source code 6 votes vote down vote up
public OrgHolder(View itemView) {
    super(itemView);
    orgImage = itemView.findViewById(R.id.org_image);
    orgCard = itemView.findViewById(R.id.card_view_org);
    orgName = itemView.findViewById(R.id.org_name);
    orgTagline = itemView.findViewById(R.id.org_tagline);

    orgCard.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent i = new Intent(context, OrgDetailActivity.class);
            i.putExtra(ORG_TAG, getItem(getAdapterPosition()));
            i.putExtra("EXTRA_TRANSITION_NAME", ViewCompat.getTransitionName(orgImage));
            ActivityOptionsCompat optionsCompat = ActivityOptionsCompat.makeSceneTransitionAnimation((AppCompatActivity) context,
                    orgImage,
                    ViewCompat.getTransitionName(orgImage));
            i.putExtra("ORG_ID", getItem(getAdapterPosition()).getOrgID());
            context.startActivity(i, optionsCompat.toBundle());
        }
    });
}
 
Example 10
Project: Neuronizer   File: RadioDialogs.java   View source code 6 votes vote down vote up
public static void showIntroDialog(final AppCompatActivity activity) {

        RadioDialogCallback callback = new RadioDialogCallback() {
            @Override
            public void which(int position) {
                if (position == 0) {
                    activity.startActivity(IntroActivity.previewIntroInstance(activity));
                    activity.finish();
                } else {
                    activity.startActivity(IntroActivity.todoListIntroInstance(activity, null, null));
                    activity.finish();
                }
            }
        };

        CharSequence[] items = new CharSequence[]{
                getString(activity, R.string.intro_preview),
                getString(activity, R.string.intro_todo_list),
        };
        showRadioDialog(activity, getString(activity, R.string.intro_dialog), items, callback);
    }
 
Example 11
Project: wallpaperboard   File: WallpaperPropertiesLoaderTask.java   View source code 6 votes vote down vote up
@Override
protected void onPostExecute(Boolean aBoolean) {
    super.onPostExecute(aBoolean);
    if (aBoolean && mContext.get() != null && !((AppCompatActivity) mContext.get()).isFinishing()) {
        if (mWallpaper.getSize() <= 0) {
            File target = ImageLoader.getInstance().getDiskCache().get(mWallpaper.getUrl());
            if (target.exists()) {
                mWallpaper.setSize((int) target.length());
            }
        }
    }

    if (mCallback != null && mCallback.get() != null) {
        mCallback.get().onPropertiesReceived(mWallpaper);
    }
}
 
Example 12
Project: simple-stack   File: ViewModelLifecycleHelper.java   View source code 5 votes vote down vote up
@NonNull
public static <T> T getViewModel(AppCompatActivity activity, String viewModelTag) {
    ViewModelHolder viewModelHolder = (ViewModelHolder) activity.getSupportFragmentManager().findFragmentByTag(viewModelTag);
    if(viewModelHolder == null) {
        throw new IllegalStateException("View model holder for [" + viewModelTag + "] does not exist");
    }
    T viewModel = viewModelHolder.getViewModel();
    if(viewModel == null) {
        throw new IllegalStateException("View model for [" + viewModelTag + "] does not exist");
    }
    return viewModel;
}
 
Example 13
Project: Guanajoven   File: RVRegionAdapter.java   View source code 5 votes vote down vote up
RegionViewHolder(View itemView) {
    super(itemView);
    tvNombreRegion = (TextView) itemView.findViewById(R.id.tv_nombre_region);
    tvDireccionRegion = (TextView) itemView.findViewById(R.id.tv_direccion_region);

    itemView.setOnClickListener(v -> {
        DetalleRegionFragment f = DetalleRegionFragment.newInstance(regiones.get(getAdapterPosition()).getIdRegion());
        FragmentManager fragmentManager = ((AppCompatActivity)context).getSupportFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.replace(R.id.segunda_fragment_container, f).addToBackStack(null).commit();
    });
}
 
Example 14
Project: Guanajoven   File: PromocionFragment.java   View source code 5 votes vote down vote up
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    activity = ((AppCompatActivity) getActivity());
    toolbar = (Toolbar) activity.findViewById(R.id.toolbar2);
    cToolBar = (CollapsingToolbarLayout) activity.findViewById(R.id.collapsing_toolbar);
}
 
Example 15
Project: DailyStudy   File: ShareTractionActivity.java   View source code 5 votes vote down vote up
private void launch(AppCompatActivity activity, View transitionView, int resId) {


        Pair squareParticipant = new Pair<>(transitionView, ViewCompat.getTransitionName(transitionView));
        ActivityOptionsCompat transitionActivityOptions =
                ActivityOptionsCompat.makeSceneTransitionAnimation(
                        activity, squareParticipant);
        Intent intent = new Intent(
                activity, ViewerActivity.class);
        intent.putExtra("resId", resId);
        startActivity(intent, transitionActivityOptions.toBundle());
    }
 
Example 16
Project: FragmentRigger   File: _Rigger.java   View source code 5 votes vote down vote up
static _Rigger create(@NonNull Object object) {
  if (object instanceof AppCompatActivity) {
    return new _ActivityRigger((AppCompatActivity) object);
  } else if (object instanceof Fragment) {
    return new _FragmentRigger((Fragment) object);
  } else {
    throw new RiggerException(
        "Puppet Annotation class can only used on android.app.Activity or android.support.v4.app.Fragment");
  }
}
 
Example 17
Project: KomaMusic   File: PlaylistAdapter.java   View source code 5 votes vote down vote up
@OnClick(R.id.iv_my_favorite)
void launchMyFavoriteDetail() {
    Intent intent = new Intent();
    intent.putExtra(Constants.WHICH_DETAIL_PAGE, Constants.MY_FAVORITE);

    ComponentName componentName = new ComponentName(Constants.MUSIC_PACKAGE_NAME,
            Constants.DETAIL_PACKAGE_NAME);

    intent.setComponent(componentName);

    mContext.startActivity(intent, ActivityOptions.makeSceneTransitionAnimation(
            ((AppCompatActivity) mContext), new Pair<View, String>(mFavorite,
                    "transition_album")).toBundle());
}
 
Example 18
Project: MusicX-music-player   File: ATE.java   View source code 5 votes vote down vote up
@SuppressWarnings("unchecked")
public static void postApply(@NonNull Activity activity, @Nullable String key) {
    if (didPreApply == null)
        preApply(activity, key);
    performMainTheming(activity, key);

    final View rootView = getRootView(activity);
    final boolean rootSetsToolbarColor = rootView != null && rootView instanceof ViewInterface &&
            ((ViewInterface) rootView).setsToolbarColor();

    if (!rootSetsToolbarColor && Config.coloredActionBar(activity, key)) {
        if (activity instanceof AppCompatActivity) {
            final AppCompatActivity aca = (AppCompatActivity) activity;
            if (aca.getSupportActionBar() != null) {
                ViewProcessor toolbarViewProcessor = getViewProcessor(Toolbar.class);
                if (toolbarViewProcessor != null) {
                    // The processor handles retrieving the toolbar from the support action bar
                    toolbarViewProcessor.process(activity, key, null, null);
                }
            }
        } else if (activity.getActionBar() != null) {
            activity.getActionBar().setBackgroundDrawable(new ColorDrawable(Config.toolbarColor(activity, key, null)));
        }
    }

    if (mPostInflationApply != null) {
        synchronized (IGNORE_TAG) {
            for (View view : mPostInflationApply) {
                if (view instanceof PostInflationApplier)
                    ((PostInflationApplier) view).postApply();
                else ATE.themeView(activity, view, key);
            }
        }
    }

    if (ATEUtil.isInClassPath(MDUtil.MAIN_CLASS))
        MDUtil.initMdSupport(activity, key);
}
 
Example 19
Project: Phoenix-for-VK   File: AbsOwnersListFragment.java   View source code 5 votes vote down vote up
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View root = inflater.inflate(mHasToolbar ? R.layout.fragment_abs_friends_with_toolbar : R.layout.fragment_abs_friends, container, false);

    if(mHasToolbar){
        ((AppCompatActivity)getActivity()).setSupportActionBar(root.findViewById(R.id.toolbar));
    }

    mRecyclerView = root.findViewById(R.id.list);
    mSwipeRefreshLayout = root.findViewById(R.id.refresh);
    mSwipeRefreshLayout.setOnRefreshListener(() -> getPresenter().fireRefresh());

    ViewUtils.setupSwipeRefreshLayoutWithCurrentTheme(getActivity(), mSwipeRefreshLayout);

    mLinearLayoutManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false);
    mRecyclerView.setLayoutManager(mLinearLayoutManager);
    mRecyclerView.addOnScrollListener(new PicassoPauseOnScrollListener(Constants.PICASSO_TAG));
    mRecyclerView.addOnScrollListener(new EndlessRecyclerOnScrollListener() {
        @Override
        public void onScrollToLastElement() {
           getPresenter().fireScrollToEnd();
        }
    });

    mOwnersAdapter = new OwnersAdapter(getActivity(), Collections.emptyList());
    mOwnersAdapter.setClickListener(owner -> getPresenter().fireOwnerClick(owner));

    mRecyclerView.setAdapter(mOwnersAdapter);
    return root;
}
 
Example 20
Project: wallpaperboard   File: LicenseCallbackHelper.java   View source code 5 votes vote down vote up
private void onLicenseChecked(LicenseHelper.Status status) {
    Preferences.get(mContext).setFirstRun(false);
    if (status == LicenseHelper.Status.SUCCESS) {
        Preferences.get(mContext).setLicensed(true);
    } else if (status == LicenseHelper.Status.FAILED) {
        Preferences.get(mContext).setLicensed(false);
        ((AppCompatActivity) mContext).finish();
    }
}
 
Example 21
Project: dkplayer   File: WindowUtil.java   View source code 5 votes vote down vote up
/**
 * 显示ActionBar,StatusBar,NavigationBar
 */
@SuppressLint("RestrictedApi")
public static void showSystemBar(final Context context) {
    scanForActivity(context).getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    showNavigationBar(context);
    AppCompatActivity appCompatActivity = getAppCompActivity(context);
    if (appCompatActivity != null) {
        ActionBar ab = appCompatActivity.getSupportActionBar();
        if (ab != null) {
            ab.setShowHideAnimationEnabled(false);
            ab.show();
        }
    }
}
 
Example 22
Project: GitHub   File: InnerBrowserFragment.java   View source code 5 votes vote down vote up
private void initViews(View view) {
    progressBar = (ProgressBar) view.findViewById(R.id.progress_bar);
    webView = (WebView) view.findViewById(R.id.web_view);
    toolbar = (Toolbar) view.findViewById(R.id.toolbar);
    AppCompatActivity activity = (AppCompatActivity) getActivity();
    activity.setSupportActionBar(toolbar);
    activity.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    textView = (TextView) view.findViewById(R.id.text_view);
    imageView = (ImageView) view.findViewById(R.id.image_view);
}
 
Example 23
Project: Cable-Android   File: ConversationFragment.java   View source code 5 votes vote down vote up
@Override
public void onItemLongClick(MessageRecord messageRecord) {
  if (actionMode == null) {
    ((ConversationAdapter) list.getAdapter()).toggleSelection(messageRecord);
    list.getAdapter().notifyDataSetChanged();

    actionMode = ((AppCompatActivity)getActivity()).startSupportActionMode(actionModeCallback);
  }
}
 
Example 24
Project: Hello-Music-droid   File: ArtistDetailFragment.java   View source code 5 votes vote down vote up
private void setupToolbar() {

        ((AppCompatActivity) getActivity()).setSupportActionBar(toolbar);

        final ActionBar ab = ((AppCompatActivity) getActivity()).getSupportActionBar();
        ab.setDisplayShowTitleEnabled(false);
        ab.setDisplayHomeAsUpEnabled(true);
    }
 
Example 25
Project: MyAnimeViewer   File: FavoritesFragment.java   View source code 5 votes vote down vote up
@Override
public void onListItemLongClick(int position) {
    if (mActionMode == null) {
        mActionMode = ((AppCompatActivity) getActivity()).startSupportActionMode(new RecordOptions((AppCompatActivity) getActivity()));
    }
    toggleSelection(position);
}
 
Example 26
Project: MyAnimeViewer   File: OfflineHistoryMaterialFragment.java   View source code 5 votes vote down vote up
@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    AppCompatActivity activity = (AppCompatActivity) getActivity();
    setHasOptionsMenu(true);

    if (activity != null) {
        mAdapter = new OfflineHistoryRecyclerAdapter(mList, getActivity(), mClickListener);
        mRecyclerView.setAdapter(mAdapter);
        //if (mAdapter == null)mAdapter = new HistoryRecyclerAdapter(mList)
        // Prepare the loader.  Either re-connect with an existing one,
        // or start a new one.
        getLoaderManager().initLoader(0, null, this);
    }

    //Restore previous state
    if (savedInstanceState != null) {
        //Selection
        mAdapter.onRestoreInstanceState(savedInstanceState);
        if (mAdapter.getSelectedItemCount() > 0) {
            mActionMode = ((AppCompatActivity) getActivity()).startSupportActionMode(new RecordOptions((AppCompatActivity) getActivity()));
        }
        //Previously serialized activated item position
        if (savedInstanceState.containsKey(STATE_ACTIVATED_POSITION))
            setSelection(savedInstanceState.getInt(STATE_ACTIVATED_POSITION));

    }
}
 
Example 27
Project: MyAnimeViewer   File: FavoritesFragment.java   View source code 5 votes vote down vote up
public void refresh() {
    AppCompatActivity activity = (AppCompatActivity) getActivity();

    if (activity != null) {
        if (mHasChanged) {
            //WriteLog.appendLog("Refreshing Favorites");
            getLoaderManager().restartLoader(0, null, this);
            mHasChanged = false;
        }
    }
}
 
Example 28
Project: TreebolicLib   File: Statusbar.java   View source code 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.M)
@SuppressWarnings({"WeakerAccess"})
protected Statusbar(@NonNull final AppCompatActivity activity0)
{
	super(activity0);
	this.activity = activity0;

	// determine orientation
	final WindowManager windowManager = (WindowManager) this.activity.getSystemService(Context.WINDOW_SERVICE);
	assert windowManager != null;
	final Display display = windowManager.getDefaultDisplay();
	final Point size = new Point();
	display.getSize(size);
	final boolean isHorizontalScreen = size.x >= size.y;
	this.isHorizontal = !isHorizontalScreen;

	// inflate
	final LayoutInflater inflater = (LayoutInflater) this.activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	assert inflater != null;
	final ViewGroup wrappedView = (ViewGroup) inflater.inflate(isHorizontalScreen ? R.layout.status_h : R.layout.status_v, this);
	this.statusView = wrappedView.findViewById(R.id.status);
	this.contentView = wrappedView.findViewById(R.id.content);
	this.contentView.setFocusable(false);

	// colors
	final int[] colors = Utils.fetchColors(this.activity, R.attr.treebolic_statusbar_background, R.attr.treebolic_statusbar_foreground, R.attr.treebolic_statusbar_foreground_icon);
	this.background = colors[0];
	this.foreground = colors[1];
	this.iconTint = colors[2];

	this.contentView.setBackgroundColor(this.background);
}
 
Example 29
Project: DebugOverlay-Android   File: ToolbarSupport.java   View source code 5 votes vote down vote up
public static void addTo(@NonNull final AppCompatActivity activity, @StringRes int toolBarTitle,
                         @ColorRes int toolBarBgColor) {
    Toolbar toolbar = getToolbar(activity);
    if (toolBarTitle != 0) {
        toolbar.setTitle(toolBarTitle);
    }
    if (toolBarBgColor != 0) {
        toolbar.setBackgroundColor(ContextCompat.getColor(activity, toolBarBgColor));
    }
    activity.setSupportActionBar(toolbar);

    if (hasParentActivity(activity)) {
        activity.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent upIntent = NavUtils.getParentActivityIntent(activity);
                if (NavUtils.shouldUpRecreateTask(activity, upIntent)) {
                    // This activity is NOT part of this app's task, so create a new task
                    // when navigating up, with a synthesized back stack.
                    TaskStackBuilder.create(activity)
                            // Add all of this activity's parents to the back stack
                            .addNextIntentWithParentStack(upIntent)
                            // Navigate up to the closest parent
                            .startActivities();
                } else {
                    // This activity is part of this app's task, so simply
                    // navigate up to the logical parent activity.
                    NavUtils.navigateUpTo(activity, upIntent);
                }
            }
        });
    }
}
 
Example 30
Project: MoligyMvpArms   File: ActivityLifecycleCallbacksImpl.java   View source code 5 votes vote down vote up
@Override
public void onActivityStarted(Activity activity) {
    Timber.w(activity + " - onActivityStarted");
    if (!activity.getIntent().getBooleanExtra("isInitToolbar", false)) {
        //由于加强框架的兼容性,故将 setContentView 放到 onActivityCreated 之后,onActivityStarted 之前执行
        //而 findViewById 必须在 Activity setContentView() 后才有效,所以将以下代码从之前的 onActivityCreated 中移动到 onActivityStarted 中执行
        activity.getIntent().putExtra("isInitToolbar", true);
        //这里全局给Activity设置toolbar和title,你想象力有多丰富,这里就有多强大,以前放到BaseActivity的操作都可以放到这里
        if (activity.findViewById(R.id.toolbar) != null) {
            if (activity instanceof AppCompatActivity) {
                ((AppCompatActivity) activity).setSupportActionBar((Toolbar) activity.findViewById(R.id.toolbar));
                ((AppCompatActivity) activity).getSupportActionBar().setDisplayShowTitleEnabled(false);
            } else {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    activity.setActionBar((android.widget.Toolbar) activity.findViewById(R.id.toolbar));
                    activity.getActionBar().setDisplayShowTitleEnabled(false);
                }
            }
        }
        if (activity.findViewById(R.id.toolbar_title) != null) {
            ((TextView) activity.findViewById(R.id.toolbar_title)).setText(activity.getTitle());
        }
        if (activity.findViewById(R.id.toolbar_back) != null) {
            activity.findViewById(R.id.toolbar_back).setOnClickListener(v -> {
                activity.onBackPressed();
            });
        }
    }
}
 
Example 31
Project: AndroidUtility   File: GoogleSignIn.java   View source code 5 votes vote down vote up
public GoogleSignIn(AppCompatActivity activity, GoogleLoginInterface googleLoginInterface) {
    GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestEmail()
            .build();

    mGoogleApiClient = new GoogleApiClient.Builder(activity)
            .enableAutoManage(activity, this)
            .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
            .build();
    this.activity = activity;
    this.googleLoginInterface = googleLoginInterface;
}
 
Example 32
Project: Cable-Android   File: ColorPreference.java   View source code 5 votes vote down vote up
@Override
protected void onClick() {
  super.onClick();

  ColorDialogFragment fragment = ColorDialogFragment.newInstance();
  fragment.setPreference(this);

  ((AppCompatActivity) getContext()).getSupportFragmentManager().beginTransaction()
                                    .add(fragment, getFragmentTag())
                                    .commit();
}
 
Example 33
Project: Task-Reminder   File: MainActivity.java   View source code 5 votes vote down vote up
@Override
public boolean onLongClick(View v) {
    AppCompatActivity activity = MainActivity.this;
    activity.startSupportActionMode(mDeleteMode);
    mMultiSelector.setSelected(this, true);
    return true;
}
 
Example 34
Project: Phoenix-for-VK   File: LogsFragement.java   View source code 5 votes vote down vote up
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View root = inflater.inflate(R.layout.fragment_logs, container, false);
    ((AppCompatActivity)getActivity()).setSupportActionBar((Toolbar) root.findViewById(R.id.toolbar));

    mSwipeRefreshLayout = (SwipeRefreshLayout) root.findViewById(R.id.refresh);
    mSwipeRefreshLayout.setOnRefreshListener(() -> getPresenter().fireRefresh());

    RecyclerView recyclerView = (RecyclerView) root.findViewById(R.id.events_recycler_view);
    recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));

    View headerView = inflater.inflate(R.layout.header_logs, recyclerView, false);

    RecyclerView typesRecyclerView = (RecyclerView) headerView.findViewById(R.id.types_recycler_view);
    typesRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.HORIZONTAL, false));

    mTypesAdapter = new HorizontalOptionsAdapter<>(Collections.emptyList());
    mTypesAdapter.setListener(this);
    typesRecyclerView.setAdapter(mTypesAdapter);

    mLogsAdapter = new LogsAdapter(Collections.emptyList(), this);
    mLogsAdapter.addHeader(headerView);

    recyclerView.setAdapter(mLogsAdapter);

    mEmptyText = (TextView) root.findViewById(R.id.empty_text);
    return root;
}
 
Example 35
Project: simple-stack   File: ViewModelLifecycleHelper.java   View source code 5 votes vote down vote up
public static <T> T bindViewModel(AppCompatActivity activity, ViewModelCreator<T> viewModelCreator, String viewModelTag) {
    ViewModelHolder viewModelHolder = (ViewModelHolder) activity.getSupportFragmentManager().findFragmentByTag(viewModelTag);
    if(viewModelHolder == null) {
        viewModelHolder = new ViewModelHolder();
        activity.getSupportFragmentManager().beginTransaction().add(viewModelHolder, viewModelTag).commitNow();
    }
    if(viewModelHolder.getViewModel() == null) {
        T t = viewModelCreator.create();
        viewModelHolder.setViewModel(t);
    }
    return viewModelHolder.getViewModel();
}
 
Example 36
Project: Guanajoven   File: ConvocatoriaFragment.java   View source code 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //Instancias de la API
    retrofit = ((MyApplication) getActivity().getApplication()).getRetrofitInstance();
    convocatoriaAPI = retrofit.create(ConvocatoriaAPI.class);
    prefs = PreferenceManager.getDefaultSharedPreferences(getActivity().getApplication());
    realm = MyApplication.getRealmInstance();

    activity = ((AppCompatActivity) getActivity());
    toolbar = (Toolbar) activity.findViewById(R.id.toolbar2);
    cToolbar = (CollapsingToolbarLayout) activity.findViewById(R.id.collapsing_toolbar);
}
 
Example 37
Project: garras   File: NavigationFragment.java   View source code 5 votes vote down vote up
@Override
public void bindEvenListener(@Nullable Bundle savedInstanceState) {
    super.bindEvenListener(savedInstanceState);
    allowSwipeBack(false);
    unbinder = ButterKnife.bind(this, viewDelegate.getRootView());
    if (getActivity() != null) {
        ((AppCompatActivity) getActivity()).setSupportActionBar(mToolbar);
        ActionBar actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar();
        if (null != actionBar) actionBar.setTitle("");
        mToolbar.setTitle("");
        setTranslate(mToolbar, DELAY * 2);
        if (UserUtils.isAuthorized()) {
            Me me = UserUtils.getMeProfile();
            if (null != me) {
                setupUserAvatar(mUserAvatar, me.profile_image);
            } else {
                setupUserAvatar(mUserAvatar, null);
            }
        } else {
            RxView.clicks(mUserAvatar).compose(NavigationFragment.this.bindUntilEvent(FragmentEvent.DESTROY_VIEW)).throttleFirst(1, TimeUnit.SECONDS).subscribe(new Consumer<Object>() {
                @SuppressLint("InflateParams")
                @Override
                public void accept(Object o) throws Exception {
                    startActivity(new Intent(getActivity(), LoginActivity.class));
                }
            });
        }

        setTranslate(mUserAvatar, DELAY * 2);
        mFragmentManager = getChildFragmentManager();
        setupFragments();
        mBottomNavigation.setOnMenuItemClickListener(this);

        setTranslate(mBottomNavigation, DELAY * 3);
    }
}
 
Example 38
Project: FriendBook   File: ToolbarHelper.java   View source code 5 votes vote down vote up
public static Toolbar initToolbar(@NonNull final AppCompatActivity activity, @IdRes int toolbarId, boolean canBack, @Nullable CharSequence title) {
    Toolbar toolbar = (Toolbar) activity.findViewById(toolbarId);
    if (toolbar == null) {
        throw new IllegalStateException(
                "The subclass of ToolbarActivity must contain a toolbar.");
    }
    activity.setSupportActionBar(toolbar);
    ActionBar actionBar = activity.getSupportActionBar();
    if (actionBar != null) {
        if (canBack) {
            actionBar.setDisplayHomeAsUpEnabled(true);
            if (title != null) {
                actionBar.setTitle(title);
            } else {
                actionBar.setDisplayShowTitleEnabled(false);
            }
            toolbar.setNavigationOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    activity.onBackPressed();
                }
            });
        }

    }
    return toolbar;
}
 
Example 39
Project: gigreminder   File: RetainedStateHolderTest.java   View source code 5 votes vote down vote up
@Test
public void createFromActivityWhenNoState() throws Exception {
    AppCompatActivity activity = mock(AppCompatActivity.class);
    when(activity.getLastCustomNonConfigurationInstance()).thenReturn(null);

    RetainedStateHolder stateHolder = RetainedStateHolder.create(activity);

    assertThat(stateHolder).isNotNull();
}
 
Example 40
Project: BAStatusBarLib   File: BAStatusBar.java   View source code 5 votes vote down vote up
/**
 * @return
 * @throws
 * @fuction 扩展到状态栏显示只能在安卓5.0以上,能用的布局也有限
 * coordinatorLayout,AppBarLayout,CollapsingToolbarLayout这种布局才有效
 * @parm
 */
@TargetApi(21)
public  void setfitsSystemWindowsBar(AppCompatActivity activity) {
    if (Build.VERSION.SDK_INT >= 21) {
        request = BarStytleBulider.getStytleBuilder(activity).setTrans().build();
        addBar();
    }
}