当前位置: 首页>>代码示例>>Java>>正文


Java Activity类代码示例

本文整理汇总了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;
    }
}
 
开发者ID:hsj-xiaokang,项目名称:OSchina_resources_android,代码行数:25,代码来源:CaptureActivityHandler.java

示例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);
}
 
开发者ID:MLNO,项目名称:airgram,代码行数:20,代码来源:DialogsActivity.java

示例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);

}
 
开发者ID:CMPUT301F17T17,项目名称:Habitizer,代码行数:27,代码来源:AddHabitActivity.java

示例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, "选择分享"));
}
 
开发者ID:coding-dream,项目名称:TPlayer,代码行数:16,代码来源:TDevice.java

示例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, ""));
        }
    }
}
 
开发者ID:fjoglar,项目名称:android-dev-challenge,代码行数:20,代码来源:SettingsFragment.java

示例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();
    }
}
 
开发者ID:archos-sa,项目名称:aos-Video,代码行数:18,代码来源:BrowserByExtStorage.java

示例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();
    }
}
 
开发者ID:zhonglikui,项目名称:cardinalsSample,代码行数:29,代码来源:GetPictureActivity.java

示例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);

}
 
开发者ID:ljlgithup,项目名称:MapDemo,代码行数:22,代码来源:MainActivity.java

示例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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:25,代码来源:PresenterManager.java

示例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);
}
 
开发者ID:kollerlukas,项目名称:Camera-Roll-Android-App,代码行数:17,代码来源:StorageUtil.java

示例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();
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:24,代码来源:CustomSportListAdapter.java

示例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();
        }
    }
    
}
 
开发者ID:turoDog,项目名称:KTalk,代码行数:22,代码来源:EaseChatRowFile.java

示例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();
}
 
开发者ID:WeGdufe,项目名称:Gdufe-Drcom-Solution,代码行数:10,代码来源:MainActivity.java

示例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();
        }
    }
}
 
开发者ID:Dnet3,项目名称:CustomAndroidOneSheeld,代码行数:13,代码来源:CameraUtils.java

示例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);
    }
}
 
开发者ID:SmartCodeLab,项目名称:SmartPermission,代码行数:12,代码来源:SmartPermission.java


注:本文中的android.app.Activity类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。