本文整理汇总了Java中android.support.v7.app.AppCompatActivity类的典型用法代码示例。如果您正苦于以下问题:Java AppCompatActivity类的具体用法?Java AppCompatActivity怎么用?Java AppCompatActivity使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AppCompatActivity类属于android.support.v7.app包,在下文中一共展示了AppCompatActivity类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onActivityResult
import android.support.v7.app.AppCompatActivity; //导入依赖的package包/类
@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);
}
}
}
示例2: init
import android.support.v7.app.AppCompatActivity; //导入依赖的package包/类
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));
}
示例3: BeaconViewFragment
import android.support.v7.app.AppCompatActivity; //导入依赖的package包/类
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);
}
};
}
示例4: onAttach
import android.support.v7.app.AppCompatActivity; //导入依赖的package包/类
@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");
}
}
示例5: onDetachedFromWindow
import android.support.v7.app.AppCompatActivity; //导入依赖的package包/类
@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();
}
示例6: getStatusBarHeight
import android.support.v7.app.AppCompatActivity; //导入依赖的package包/类
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;
}
示例7: init
import android.support.v7.app.AppCompatActivity; //导入依赖的package包/类
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);
}
示例8: TitleLayout
import android.support.v7.app.AppCompatActivity; //导入依赖的package包/类
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());
}
}
示例9: OrgHolder
import android.support.v7.app.AppCompatActivity; //导入依赖的package包/类
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());
}
});
}
示例10: showIntroDialog
import android.support.v7.app.AppCompatActivity; //导入依赖的package包/类
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);
}
示例11: onPostExecute
import android.support.v7.app.AppCompatActivity; //导入依赖的package包/类
@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);
}
}
示例12: getViewModel
import android.support.v7.app.AppCompatActivity; //导入依赖的package包/类
@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;
}
示例13: RegionViewHolder
import android.support.v7.app.AppCompatActivity; //导入依赖的package包/类
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();
});
}
示例14: onCreate
import android.support.v7.app.AppCompatActivity; //导入依赖的package包/类
@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);
}
示例15: launch
import android.support.v7.app.AppCompatActivity; //导入依赖的package包/类
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());
}