本文整理匯總了Java中android.app.Activity.getClass方法的典型用法代碼示例。如果您正苦於以下問題:Java Activity.getClass方法的具體用法?Java Activity.getClass怎麽用?Java Activity.getClass使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.app.Activity
的用法示例。
在下文中一共展示了Activity.getClass方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: isSupportActivity
import android.app.Activity; //導入方法依賴的package包/類
private static boolean isSupportActivity(Activity activity) {
boolean isSupport = false;
for (Class<?> c = activity.getClass().getSuperclass();; c = c.getSuperclass()) {
if (c == null) {
throw new RuntimeException("Illegal activity type: " + activity.getClass());
}
String name = c.getName();
if (name.equals("android.support.v4.app.FragmentActivity")) {
isSupport = true;
break;
} else if (name.startsWith("com.actionbarsherlock.app")
&& (name.endsWith(".SherlockActivity") || name.endsWith(".SherlockListActivity") || name
.endsWith(".SherlockPreferenceActivity"))) {
throw new RuntimeException("Please use SherlockFragmentActivity. Illegal activity: " + name);
} else if (name.equals("android.app.Activity")) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
throw new RuntimeException(
"Illegal activity without fragment support. Either use Android 3.0+ or android.support.v4.app.FragmentActivity.");
}
break;
}
}
return isSupport;
}
示例2: injectView
import android.app.Activity; //導入方法依賴的package包/類
private static void injectView(Activity activity) {
Class<? extends Activity> clazz = activity.getClass();
// 獲取所有的成員變量
Field[] fields = clazz.getDeclaredFields();
for (Field field : fields) {
ViewInject inject = field.getAnnotation(ViewInject.class);
if (inject != null) {
int viewId = inject.value();
View view = activity.findViewById(viewId);
field.setAccessible(true);
try {
field.set(activity, view);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
}
}
示例3: ActionBarHelper
import android.app.Activity; //導入方法依賴的package包/類
public ActionBarHelper(Activity activity) {
mActivity = activity;
try {
Class clazz = activity.getClass();
Method m = clazz.getMethod("getSupportActionBar");
mUsesCompat = true;
} catch (NoSuchMethodException e) {
if (DEBUG) {
Log.e(TAG,
"Activity " + activity.getClass().getSimpleName() + " does not use a compatibility action bar",
e);
}
}
mIndicatorInfo = getIndicatorInfo();
}
示例4: isSupportActivity
import android.app.Activity; //導入方法依賴的package包/類
private static boolean isSupportActivity(Activity activity) {
Class<?> c = activity.getClass().getSuperclass();
while (c != null) {
String name = c.getName();
if (name.equals("android.support.v4.app.FragmentActivity")) {
return true;
}
if (name.startsWith("com.actionbarsherlock.app") && (name.endsWith(".SherlockActivity") || name.endsWith(".SherlockListActivity") || name.endsWith(".SherlockPreferenceActivity"))) {
throw new RuntimeException("Please use SherlockFragmentActivity. Illegal activity: " + name);
} else if (!name.equals("android.app.Activity")) {
c = c.getSuperclass();
} else if (VERSION.SDK_INT >= 11) {
return false;
} else {
throw new RuntimeException("Illegal activity without fragment support. Either use Android 3.0+ or android.support.v4.app.FragmentActivity.");
}
}
throw new RuntimeException("Illegal activity type: " + activity.getClass());
}
示例5: buildMembersList
import android.app.Activity; //導入方法依賴的package包/類
private Content buildMembersList() {
try {
Activity activity = CommonUtils.getCurrentActivity();
if (activity == null) {
return new ErrorPage("Activity not available for listing").getContent();
} else {
Class clazz = activity.getClass();
Content content = new Content();
content.add(new HeadingContentPart(4, "Fields"));
content.add(getFieldsList(activity, clazz));
content.add(new HeadingContentPart(4, "Methods"));
content.add(getMethodsList(clazz));
return content;
}
} catch (Exception e) {
e.printStackTrace();
return new ErrorPage(e.getMessage()).getContent();
}
}
示例6: onAttach
import android.app.Activity; //導入方法依賴的package包/類
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
context = activity.getApplicationContext();
try {
fragmentListener = (MessageListFragmentListener) activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity.getClass() +
" must implement MessageListFragmentListener");
}
}
示例7: getAppThemeExpanded
import android.app.Activity; //導入方法依賴的package包/類
/**
* Manipulate the application theme with TRASLUCENT actionbar:
* Based on the corresponding theme (1-7) this method will:
* set the theme
* colorize the actionbar accordinlgy
* adjust the padding of the icon
* colorize (if >lollipop) the multitask
* colorize (if>KK) the statusbar
* <p/>
* this returns a drawable that corresponds to the actionbar background
* later to be manipulated by the corresponding activity
*
* @param context
*/
public static Drawable getAppThemeExpanded(final Activity context,
Drawable mActionBarBackgroundDrawable) {
int Theme = Integer.valueOf(PreferenceManager
.getDefaultSharedPreferences(context).getString(
PreferencesActivity.KEY_THEME, "3"));
mActionBarBackgroundDrawable = getThemeDrawable(context, Theme);
if (Theme == 4) {
context.setTheme(R.style.BlackTheme55);
} else if (Theme == 1 || Theme == 7) {
context.setTheme(R.style.CustomTheme55);
context.getActionBar().setSplitBackgroundDrawable(
mActionBarBackgroundDrawable);
context.getActionBar().setStackedBackgroundDrawable(
mActionBarBackgroundDrawable);
} else {
context.setTheme(R.style.ThunderMusic55);
context.getActionBar().setSplitBackgroundDrawable(
mActionBarBackgroundDrawable);
context.getActionBar().setStackedBackgroundDrawable(
mActionBarBackgroundDrawable);
}
ImageView view = (ImageView) context.findViewById(android.R.id.home);
int paddingRight;
if (context.getClass() == MediaPlaybackActivity.class) {
paddingRight = (int) TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP, 16, context.getResources()
.getDisplayMetrics());
} else {
paddingRight = (int) TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP, 24, context.getResources()
.getDisplayMetrics());
}
int paddingLeft = (int) TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP, 21, context.getResources()
.getDisplayMetrics());
view.setPadding(paddingLeft, 0, paddingRight, 0);
mActionBarBackgroundDrawable.setAlpha(0);
context.getActionBar().setIcon(R.drawable.ic_action_back);
context.getActionBar().setBackgroundDrawable(
mActionBarBackgroundDrawable);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
if (Theme < 6)
context.setTaskDescription(new ActivityManager.TaskDescription(
context.getString(R.string.musicbrowserlabel),
BitmapFactory.decodeResource(context.getResources(),
R.drawable.app_music), context.getResources()
.getColor(getThemeColor(context, Theme))));
else
context.setTaskDescription(new ActivityManager.TaskDescription(
context.getString(R.string.musicbrowserlabel),
BitmapFactory.decodeResource(context.getResources(),
R.drawable.app_music), getThemeColor(context,
Theme)));
}
return mActionBarBackgroundDrawable;
}
示例8: getSpecialActivity
import android.app.Activity; //導入方法依賴的package包/類
/**
* 調用此方法前請務必確認activity在堆棧中,否則將死循環
* @param cls
* @return
*/
public Activity getSpecialActivity(Class<?> cls) {
for (Activity activity:mActivityStack) {
if (cls == activity.getClass()) {
return activity;
}
}
return null;
}
示例9: setupForegroundDispatch
import android.app.Activity; //導入方法依賴的package包/類
private static void setupForegroundDispatch(final Activity activity, NfcAdapter adapter)
{
final Intent intent = new Intent(activity.getApplicationContext(), activity.getClass());
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
final PendingIntent pendingIntent = PendingIntent.getActivity(activity.getApplicationContext(), 0, intent, 0);
IntentFilter[] filters = new IntentFilter[1];
String[][] techList = new String[][]{};
filters[0] = new IntentFilter();
filters[0].addAction(NfcAdapter.ACTION_NDEF_DISCOVERED);
filters[0].addCategory(Intent.CATEGORY_DEFAULT);
try
{
/* Mime type for BT pairing */
filters[0].addDataType("application/vnd.bluetooth.ep.oob");
}
catch (IntentFilter.MalformedMimeTypeException e)
{
throw new RuntimeException("Unsupported mime type!");
}
/* Start Foreground dispatcher */
adapter.enableForegroundDispatch(activity, pendingIntent, filters, techList);
}
示例10: createPendingIntent
import android.app.Activity; //導入方法依賴的package包/類
private void createPendingIntent() {
if (pendingIntent == null) {
Activity activity = getActivity();
Intent intent = new Intent(activity, activity.getClass());
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
pendingIntent = PendingIntent.getActivity(activity, 0, intent, 0);
}
}
開發者ID:RoopeHakulinen,項目名稱:cordova-plugin-mifare-ultralight,代碼行數:9,代碼來源:CordovaPluginMifareUltralight.java
示例11: restoreApp
import android.app.Activity; //導入方法依賴的package包/類
private static void restoreApp(Activity activity) {
Intent i = new Intent(activity, activity.getClass());
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
i.addFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
i.addFlags(Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY);
i.addCategory(Intent.CATEGORY_LAUNCHER);
activity.startActivity(i);
}
示例12: setActivity
import android.app.Activity; //導入方法依賴的package包/類
public static void setActivity(Activity activity, Class<? extends Activity> claz) {
context = activity.getApplicationContext();
activityClass = claz == null ? activity.getClass() : claz;
}
示例13: attachTo
import android.app.Activity; //導入方法依賴的package包/類
/** Scope is limited to the activity's class. */
public static void attachTo(Activity activity, boolean finishAfterDialog, Bundle argumentsForErrorDialog) {
Object executionScope = activity.getClass();
attachTo(activity, executionScope, finishAfterDialog, argumentsForErrorDialog);
}