本文整理汇总了Java中android.app.Activity类的典型用法代码示例。如果您正苦于以下问题:Java Activity类的具体用法?Java Activity怎么用?Java Activity使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Activity类属于android.app包,在下文中一共展示了Activity类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleMessage
import android.app.Activity; //导入依赖的package包/类
@Override
public void handleMessage(Message message) {
switch (message.what) {
case R.id.restart_preview:
restartPreviewAndDecode();
break;
case R.id.decode_succeeded:
state = State.SUCCESS;
Bundle bundle = message.getData();
activity.handleDecode((Result) message.obj, bundle);
break;
case R.id.decode_failed:
// We're decoding as fast as possible, so when one decode fails,
// start another.
state = State.PREVIEW;
cameraManager.requestPreviewFrame(decodeThread.getHandler(), R.id.decode);
break;
case R.id.return_scan_result:
activity.setResult(Activity.RESULT_OK, (Intent) message.obj);
activity.finish();
break;
}
}
示例2: askForPermissons
import android.app.Activity; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.M)
private void askForPermissons() {
Activity activity = getParentActivity();
if (activity == null) {
return;
}
ArrayList<String> permissons = new ArrayList<>();
if (activity.checkSelfPermission(Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) {
permissons.add(Manifest.permission.READ_CONTACTS);
permissons.add(Manifest.permission.WRITE_CONTACTS);
permissons.add(Manifest.permission.GET_ACCOUNTS);
}
if (activity.checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
permissons.add(Manifest.permission.READ_EXTERNAL_STORAGE);
permissons.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
}
String[] items = permissons.toArray(new String[permissons.size()]);
activity.requestPermissions(items, 1);
}
示例3: setUpDays
import android.app.Activity; //导入依赖的package包/类
/**
* Sets up view for showing completed days
* @param ctx
*/
public static void setUpDays(Activity ctx) {
LinearLayout daysOuter = (LinearLayout) ctx.findViewById(R.id.days_outer);
View childdays = ctx.getLayoutInflater().inflate(R.layout.days, null);
// Setting things
for (int i = 0; i < 7; i++) {
final TextView dayTextView = (TextView) childdays.findViewById(AddHabitActivity.daytags[i]);
final int currenti = i;
if (AddHabitActivity.days[i] == 1) {
dayTextView.setBackground(ctx.getDrawable(R.drawable.days_border_valid));
}
}
LinearLayout daysInner = (LinearLayout) childdays.findViewById(R.id.days_inner);
daysInner.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT));
daysOuter.addView(childdays);
}
示例4: showSystemShareOption
import android.app.Activity; //导入依赖的package包/类
/**
* 调用系统安装了的应用分享
*
* @param context
* @param title
* @param url
*/
public static void showSystemShareOption(Activity context,
final String title, final String url) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_SUBJECT, "分享:" + title);
intent.putExtra(Intent.EXTRA_TEXT, title + " " + url);
context.startActivity(Intent.createChooser(intent, "选择分享"));
}
示例5: onSharedPreferenceChanged
import android.app.Activity; //导入依赖的package包/类
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
Activity activity = getActivity();
if (key.equals(getString(R.string.pref_location_key))) {
// we've changed the location
// Wipe out any potential PlacePicker latlng values so that we can use this text entry.
SunshinePreferences.resetLocationCoordinates(activity);
} else if (key.equals(getString(R.string.pref_units_key))) {
// units have changed. update lists of weather entries accordingly
activity.getContentResolver().notifyChange(WeatherContract.WeatherEntry.CONTENT_URI, null);
}
Preference preference = findPreference(key);
if (null != preference) {
if (!(preference instanceof CheckBoxPreference)) {
setPreferenceSummary(preference, sharedPreferences.getString(key, ""));
}
}
}
示例6: onActivityResult
import android.app.Activity; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.KITKAT)
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
if(requestCode==READ_REQUEST_CODE) {
if (resultCode == Activity.RESULT_OK) {
//Set directory as default in preferences
Uri treeUri = intent.getData();
//grant write permissions
getActivity().getContentResolver().takePersistableUriPermission(treeUri, Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
mCurrentDirectory = treeUri;
listFiles(false);
getLoaderManager().restartLoader(0, null, this);
} else displayFailPage();
}
}
示例7: resultImage
import android.app.Activity; //导入依赖的package包/类
/**
* 获取图片成功后进行处理
*
* @param imagePath 图片路径
*/
private void resultImage(String imagePath) {
Bitmap bitmap;
if (!TextUtils.isEmpty(imagePath)) {
bitmap = ImageUtil.getImageThumbnail(imagePath, IMAGE_MAX_SIZE, IMAGE_MAX_SIZE);
String filePath = new File(SDUtil.getFileDir(), "temp2.jpg").getAbsolutePath();
ImageUtil.saveImage(bitmap, filePath, 50);
// deleteTempPicture();
Logger.d("处理图片" + filePath);
Intent resultIntent = new Intent();
resultIntent.putExtra(IMAGE_PATH, filePath);
setResult(Activity.RESULT_OK, resultIntent);
GetPictureActivity.this.finish();
} else {
//没有获取到文件的路径
ToastUtil.showShort("图片获取失败");
setResult(Activity.RESULT_CANCELED);
finish();
}
}
示例8: onJumpToNavigator
import android.app.Activity; //导入依赖的package包/类
@Override
public void onJumpToNavigator() {
/*
* 设置途径点以及resetEndNode会回调该接口
*/
for (Activity ac : activityList) {
if (ac.getClass().getName().endsWith("BNDemoGuideActivity")) {
return;
}
}
Intent intent = new Intent(MainActivity.this,
BNDemoGuideActivity.class);
Bundle bundle = new Bundle();
bundle.putSerializable(ROUTE_PLAN_NODE, mBNRoutePlanNode);
intent.putExtras(bundle);
startActivity(intent);
}
示例9: onActivityDestroyed
import android.app.Activity; //导入依赖的package包/类
@Override public void onActivityDestroyed(Activity activity) {
if (!activity.isChangingConfigurations()) {
// Activity will be destroyed permanently, so reset the cache
String activityId = activityIdMap.get(activity);
if (activityId != null) {
ActivityScopedCache scopedCache = activityScopedCacheMap.get(activityId);
if (scopedCache != null) {
scopedCache.clear();
activityScopedCacheMap.remove(activityId);
}
// No Activity Scoped cache available, so unregister
if (activityScopedCacheMap.isEmpty()) {
// All Mosby related activities are destroyed, so we can remove the activity lifecylce listener
activity.getApplication()
.unregisterActivityLifecycleCallbacks(activityLifecycleCallbacks);
if (DEBUG) {
Log.d(DEBUG_TAG, "Unregistering ActivityLifecycleCallbacks");
}
}
}
}
activityIdMap.remove(activity);
}
示例10: loadRoots
import android.app.Activity; //导入依赖的package包/类
public static StorageRoot[] loadRoots(Activity context) {
ArrayList<StorageRoot> temp = new ArrayList<>();
StorageRoot externalStorage = new StorageRoot(
Environment.getExternalStorageDirectory().getPath());
externalStorage.setName(context.getString(R.string.storage));
temp.add(externalStorage);
File[] removableStorageRoots = getRemovableStorageRoots(context);
for (int i = 0; i < removableStorageRoots.length; i++) {
temp.add(new StorageRoot(removableStorageRoots[i].getPath()));
}
StorageRoot[] roots = new StorageRoot[temp.size()];
return temp.toArray(roots);
}
示例11: onClick
import android.app.Activity; //导入依赖的package包/类
public void onClick(View v) {
new Builder(CustomSportListAdapter.this.context).setMessage("确定要删除吗?")
.setPositiveButton("删除", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
if (CustomSportListAdapter.this.data != null) {
FoodApi.deleteCustomActivities(((CustomSport) CustomSportListAdapter.this
.data.get(DelListener.this.position)).id, CustomSportListAdapter
.this.context, new JsonCallback((Activity) CustomSportListAdapter
.this.context) {
public void onFinish() {
super.onFinish();
}
public void ok(JSONObject object) {
super.ok(object);
CustomSportListAdapter.this.remove(DelListener.this.position);
CustomSportListAdapter.this.notifyDataSetChanged();
}
});
}
}
}).setNegativeButton("取消", null).show();
}
示例12: onBubbleClick
import android.app.Activity; //导入依赖的package包/类
@Override
protected void onBubbleClick() {
String filePath = fileMessageBody.getLocalUrl();
File file = new File(filePath);
if (file.exists()) {
// open files if it exist
FileUtils.openFile(file, (Activity) context);
} else {
// download the file
context.startActivity(new Intent(context, EaseShowNormalFileActivity.class).putExtra("msg", message));
}
if (message.direct() == EMMessage.Direct.RECEIVE && !message.isAcked() && message.getChatType() == ChatType.Chat) {
try {
EMClient.getInstance().chatManager().ackMessageRead(message.getFrom(), message.getMsgId());
} catch (HyphenateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
示例13: forgotPsw
import android.app.Activity; //导入依赖的package包/类
private void forgotPsw() {
SharedPreferences sp = getSharedPreferences(PREFERENCES_NAME, Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = sp.edit();
editor.clear();
editor.commit();
ed_acc.setText("");
ed_psw.setText("");
Toast.makeText(MainActivity.this, "已清除缓存", Toast.LENGTH_SHORT).show();
}
示例14: setLastCapturedImagePathFromOneSheeldFolder
import android.app.Activity; //导入依赖的package包/类
public static void setLastCapturedImagePathFromOneSheeldFolder(String lastCapturedImagePathFromOneSheeldFolder,Activity activity) {
sharedPreferences = activity.getSharedPreferences("camera",Context.MODE_PRIVATE);
if (lastCapturedImagePathFromOneSheeldFolder != null) {
File tmpImage = new File(lastCapturedImagePathFromOneSheeldFolder);
if (tmpImage.exists()) {
CameraUtils.lastCapturedImagePathFromOneSheeldFolder = lastCapturedImagePathFromOneSheeldFolder;
editor = sharedPreferences.edit();
editor.putString(sharedPreferencesKey,lastCapturedImagePathFromOneSheeldFolder);
editor.commit();
}
}
}
示例15: executePermissionsRequest
import android.app.Activity; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.M)
private void executePermissionsRequest() {
checkObjectsValid(mObject);
if (mObject instanceof Activity) {
ActivityCompat.requestPermissions((Activity) mObject, mPermissions, mRequestPermissionCode);
} else if (mObject instanceof android.support.v4.app.Fragment) {
((android.support.v4.app.Fragment) mObject).requestPermissions(mPermissions, mRequestPermissionCode);
} else if (mObject instanceof android.app.Fragment) {
((android.app.Fragment) mObject).requestPermissions(mPermissions, mRequestPermissionCode);
}
}