當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。