android.util.TypedValue#complexToDimensionPixelSize ( )源码实例Demo

下面列出了android.util.TypedValue#complexToDimensionPixelSize ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: redgram-for-reddit   文件: SearchFragment.java
private void setupSwipeContainer(){
    //disable it for search fragment
    searchSwipeContainer.setEnabled(false);
    searchSwipeContainer.setColorSchemeResources(android.R.color.holo_green_dark,
            android.R.color.holo_red_dark,
            android.R.color.holo_blue_dark,
            android.R.color.holo_orange_dark);

    TypedValue tv = new TypedValue();
    if (getContext().getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true))
    {
        int actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data,
                getContext().getResources().getDisplayMetrics());
        //push it down to the same position as the first item to be loaded
        searchSwipeContainer.setProgressViewOffset(false, 0 , 50);
    }
}
 
源代码2 项目: Mizuu   文件: MizLib.java
/**
 * Add a margin with a combined height of the ActionBar and Status bar to the top of a given View contained in a FrameLayout
 * @param c
 * @param v
 */
public static void addActionBarAndStatusBarMargin(Context c, View v, FrameLayout.LayoutParams layoutParams) {
    int mActionBarHeight = 0, mStatusBarHeight = 0;
    TypedValue tv = new TypedValue();
    if (c.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true))
        mActionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, c.getResources().getDisplayMetrics());
    else
        mActionBarHeight = 0; // No ActionBar style (pre-Honeycomb or ActionBar not in theme)

    if (hasKitKat())
        mStatusBarHeight = convertDpToPixels(c, 25);

    FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    params.setMargins(0, mActionBarHeight + mStatusBarHeight, 0, 0);
    params.gravity = layoutParams.gravity;
    v.setLayoutParams(params);
}
 
源代码3 项目: MNImageBrowser   文件: BarConfig.java
@TargetApi(14)
private int getActionBarHeight(Activity activity) {
    int result = 0;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        View actionBar = activity.getWindow().findViewById(R.id.action_bar_container);
        if (actionBar != null) {
            result = actionBar.getMeasuredHeight();
        }
        if (result == 0) {
            TypedValue tv = new TypedValue();
            activity.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true);
            result = TypedValue.complexToDimensionPixelSize(tv.data, activity.getResources().getDisplayMetrics());
        }
    }
    return result;
}
 
源代码4 项目: weex   文件: ScreenShot.java
public static  int getActionBarHeight(Activity activity) {
    int actionBarHeight = 0;
    if(activity.getActionBar()!= null){
        actionBarHeight = activity.getActionBar().getHeight();
    }

    if (actionBarHeight != 0)
        return actionBarHeight;

    final TypedValue tv = new TypedValue();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        if (activity.getTheme().resolveAttribute(android.support.v7.appcompat.R.attr.actionBarSize, tv, true)){
            actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, activity.getResources().getDisplayMetrics());
            Log.e("actionBarHeight==",actionBarHeight +  "android.support.v7.appcompat.R.attr.actionBarSize");

        }

        else if (activity.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)){
            actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, activity.getResources().getDisplayMetrics());
            Log.e("actionBarHeight==",actionBarHeight +  "actionBarHeight is android.R.attr.actionBarSize");

        }
    }

    return actionBarHeight;
}
 
源代码5 项目: SweetTips   文件: ScreenUtil.java
/**
 * 获取actionbar的像素高度,默认使用android官方兼容包做actionbar兼容
 *
 * @return
 */
public static int getActionBarHeight(Context context) {
    int actionBarHeight=0;
    if(context instanceof AppCompatActivity &&((AppCompatActivity) context).getSupportActionBar()!=null) {
        Log.d("isAppCompatActivity", "==AppCompatActivity");
        actionBarHeight = ((AppCompatActivity) context).getSupportActionBar().getHeight();
    }else if(context instanceof Activity && ((Activity) context).getActionBar()!=null) {
        Log.d("isActivity","==Activity");
        actionBarHeight = ((Activity) context).getActionBar().getHeight();
    }else if(context instanceof ActivityGroup){
        Log.d("ActivityGroup","==ActivityGroup");
        if (((ActivityGroup) context).getCurrentActivity() instanceof AppCompatActivity && ((AppCompatActivity) ((ActivityGroup) context).getCurrentActivity()).getSupportActionBar()!=null){
            actionBarHeight = ((AppCompatActivity) ((ActivityGroup) context).getCurrentActivity()).getSupportActionBar().getHeight();
        }else if (((ActivityGroup) context).getCurrentActivity() instanceof Activity && ((Activity) ((ActivityGroup) context).getCurrentActivity()).getActionBar()!=null){
            actionBarHeight = ((Activity) ((ActivityGroup) context).getCurrentActivity()).getActionBar().getHeight();
        }
    }
    if (actionBarHeight != 0)
        return actionBarHeight;
    final TypedValue tv = new TypedValue();
    if(context.getTheme().resolveAttribute( android.support.v7.appcompat.R.attr.actionBarSize, tv, true)){
        if (context.getTheme().resolveAttribute(android.support.v7.appcompat.R.attr.actionBarSize, tv, true))
            actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, context.getResources().getDisplayMetrics());
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        if (context.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true))
            actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, context.getResources().getDisplayMetrics());
    }else {
        if (context.getTheme().resolveAttribute(android.support.v7.appcompat.R.attr.actionBarSize, tv, true))
            actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, context.getResources().getDisplayMetrics());
    }
    Log.d("actionBarHeight","===="+actionBarHeight);
    return actionBarHeight;
}
 
@TargetApi(14)
private int getActionBarHeight(Context context) {
    int result = 0;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        TypedValue tv = new TypedValue();
        context.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true);
        result = TypedValue.complexToDimensionPixelSize(tv.data, context.getResources().getDisplayMetrics());
    }
    return result;
}
 
源代码7 项目: AndroidSchool   文件: MoviesActivity.java
@NonNull
private MoviesAdapter createAdapter() {
    TypedValue typedValue = new TypedValue();
    getResources().getValue(R.dimen.rows_count, typedValue, true);
    float rowsCount = typedValue.getFloat();
    int actionBarHeight = getTheme().resolveAttribute(R.attr.actionBarSize, typedValue, true)
            ? TypedValue.complexToDimensionPixelSize(typedValue.data, getResources().getDisplayMetrics())
            : 0;
    int imageHeight = (int) ((getResources().getDisplayMetrics().heightPixels - actionBarHeight) / rowsCount);

    int columns = getResources().getInteger(R.integer.columns_count);
    int imageWidth = getResources().getDisplayMetrics().widthPixels / columns;

    return new MoviesAdapter(imageHeight, imageWidth, this);
}
 
源代码8 项目: ChipHellClient   文件: QuickReturnUtils.java
public static int getActionBarHeight(Context context) {
    if (sActionBarHeight != 0) {
        return sActionBarHeight;
    }

    context.getTheme().resolveAttribute(android.R.attr.actionBarSize, sTypedValue, true);
    sActionBarHeight = TypedValue.complexToDimensionPixelSize(sTypedValue.data, context.getResources().getDisplayMetrics());
    return sActionBarHeight;
}
 
源代码9 项目: PocketEOS-Android   文件: BarConfig.java
@TargetApi(14)
private int getActionBarHeight(Context context) {
    int result = 0;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        TypedValue tv = new TypedValue();
        context.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true);
        result = TypedValue.complexToDimensionPixelSize(tv.data, context.getResources().getDisplayMetrics());
    }
    return result;
}
 
源代码10 项目: ShaderEditor   文件: SystemBarMetrics.java
public static int getToolBarHeight(Context context) {
	TypedValue tv = new TypedValue();
	return context.getTheme().resolveAttribute(
			android.R.attr.actionBarSize,
			tv,
			true) ? TypedValue.complexToDimensionPixelSize(
			tv.data,
			context.getResources().getDisplayMetrics()) : 0;
}
 
源代码11 项目: android_9.0.0_r45   文件: AppWidgetProviderInfo.java
/**
 * @hide
 */
public void updateDimensions(DisplayMetrics displayMetrics) {
    // Converting complex to dp.
    minWidth = TypedValue.complexToDimensionPixelSize(minWidth, displayMetrics);
    minHeight = TypedValue.complexToDimensionPixelSize(minHeight, displayMetrics);
    minResizeWidth = TypedValue.complexToDimensionPixelSize(minResizeWidth, displayMetrics);
    minResizeHeight = TypedValue.complexToDimensionPixelSize(minResizeHeight, displayMetrics);
}
 
源代码12 项目: WanAndroid   文件: ViewHelper.java
public static int getSystemActionBarSize(Context context) {
    TypedValue tv = new TypedValue();
    if (context.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
        return TypedValue.complexToDimensionPixelSize(tv.data, context.getResources().getDisplayMetrics());
    } else {
        return dpToPx(context, 48);
    }
}
 
源代码13 项目: LLApp   文件: OtherUtils.java
public static int getActionBarHeight(Context context) {
//        int contentTop = activity.getWindow().findViewById(Window.ID_ANDROID_CONTENT).getTop();
//        //statusBarHeight是上面状态栏的高度
////        int titleBarHeight = contentTop - statusBarHeight;
//        return contentTop;
        int actionBarHeight = 0;
        TypedValue tv = new TypedValue();
        if (context.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
            actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, context.getResources().getDisplayMetrics());
        }
        return actionBarHeight;

    }
 
源代码14 项目: syncthing-android   文件: MainActivity.java
/**
 * Calculating width based on
 * http://www.google.com/design/spec/patterns/navigation-drawer.html#navigation-drawer-specs.
 */
private void setOptimalDrawerWidth(View drawerContainer) {
    int actionBarSize = 0;
    TypedValue tv = new TypedValue();
    if (getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
        actionBarSize = TypedValue.complexToDimensionPixelSize(tv.data,getResources().getDisplayMetrics());
    }

    ViewGroup.LayoutParams params = drawerContainer.getLayoutParams();
    DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
    int minScreenWidth = min(displayMetrics.widthPixels, displayMetrics.heightPixels);

    params.width = min(minScreenWidth - actionBarSize, 5 * actionBarSize);
    drawerContainer.requestLayout();
}
 
源代码15 项目: NestedTouchScrollingLayout   文件: DisplayUtils.java
public static int getActionBarHeightPixels(final Context pContext) {
    final TypedValue typedValue = new TypedValue();

    if (pContext != null && pContext.getTheme().resolveAttribute(android.R.attr.actionBarSize, typedValue, true)) {
        return TypedValue.complexToDimensionPixelSize(typedValue.data, pContext.getResources().getDisplayMetrics());
    }

    return 0;
}
 
源代码16 项目: Android-utils   文件: BarUtils.java
/**
 * Return the action bar's height.
 *
 * @return the action bar's height
 */
public static int getActionBarHeight() {
    TypedValue tv = new TypedValue();
    if (UtilsApp.getApp().getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
        return TypedValue.complexToDimensionPixelSize(
                tv.data, UtilsApp.getApp().getResources().getDisplayMetrics()
        );
    }
    return 0;
}
 
源代码17 项目: DevUtils   文件: BarUtils.java
/**
 * 获取 ActionBar 高度
 * @return ActionBar 高度
 */
public static int getActionBarHeight() {
    TypedValue tv = new TypedValue();
    try {
        if (DevUtils.getContext().getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
            return TypedValue.complexToDimensionPixelSize(tv.data, Resources.getSystem().getDisplayMetrics());
        }
    } catch (Exception e) {
        LogPrintUtils.eTag(TAG, e, "getActionBarHeight");
    }
    return 0;
}
 
源代码18 项目: Tweetin   文件: ViewUnit.java
public static int getToolbarHeight(Context context) {
    TypedValue typedValue = new TypedValue();

    if (context.getTheme().resolveAttribute(android.R.attr.actionBarSize, typedValue, true)) {
        return TypedValue.complexToDimensionPixelSize(typedValue.data, context.getResources().getDisplayMetrics());
    }

    return 0;
}
 
源代码19 项目: YiZhi   文件: ScreenUtils.java
/**
 * 获取actionbar的像素高度,默认使用android官方兼容包做actionbar兼容
 *
 * @return
 */
public static int getActionBarHeight(Context context) {
    int actionBarHeight = 0;
    if (context instanceof AppCompatActivity && ((AppCompatActivity) context)
            .getSupportActionBar() != null) {
        Log.d("isAppCompatActivity", "==AppCompatActivity");
        actionBarHeight = ((AppCompatActivity) context).getSupportActionBar().getHeight();
    } else if (context instanceof Activity && ((Activity) context).getActionBar() != null) {
        Log.d("isActivity", "==Activity");
        actionBarHeight = ((Activity) context).getActionBar().getHeight();
    } else if (context instanceof ActivityGroup) {
        Log.d("ActivityGroup", "==ActivityGroup");
        if (((ActivityGroup) context).getCurrentActivity() instanceof AppCompatActivity && (
                (AppCompatActivity) ((ActivityGroup) context).getCurrentActivity())
                .getSupportActionBar() != null) {
            actionBarHeight = ((AppCompatActivity) ((ActivityGroup) context)
                    .getCurrentActivity()).getSupportActionBar().getHeight();
        } else if (((ActivityGroup) context).getCurrentActivity() instanceof Activity && (
                (Activity) ((ActivityGroup) context).getCurrentActivity()).getActionBar() !=
                null) {
            actionBarHeight = ((Activity) ((ActivityGroup) context).getCurrentActivity())
                    .getActionBar().getHeight();
        }
    }
    if (actionBarHeight != 0)
        return actionBarHeight;
    final TypedValue tv = new TypedValue();
    if (context.getTheme().resolveAttribute(android.support.v7.appcompat.R.attr
            .actionBarSize, tv, true)) {
        if (context.getTheme().resolveAttribute(android.support.v7.appcompat.R.attr
                .actionBarSize, tv, true))
            actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, context
                    .getResources().getDisplayMetrics());
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        if (context.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true))
            actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, context
                    .getResources().getDisplayMetrics());
    } else {
        if (context.getTheme().resolveAttribute(android.support.v7.appcompat.R.attr
                .actionBarSize, tv, true))
            actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, context
                    .getResources().getDisplayMetrics());
    }
    Log.d("actionBarHeight", "====" + actionBarHeight);
    return actionBarHeight;
}
 
源代码20 项目: chromadoze   文件: ChromaDoze.java
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    mUiState = new UIState(getApplication());

    SharedPreferences pref = getSharedPreferences(PREF_NAME, MODE_PRIVATE);
    mUiState.loadState(pref);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setTitle("");

    mNavSpinner = (Spinner) findViewById(R.id.nav_spinner);
    ArrayAdapter<String> adapter = new ArrayAdapter<>(
            actionBar.getThemedContext(), R.layout.spinner_title,
            FragmentIndex.getStrings(this));
    adapter.setDropDownViewResource(R.layout.support_simple_spinner_dropdown_item);
    mNavSpinner.setAdapter(adapter);
    mNavSpinner.setOnItemSelectedListener(this);


    // Created a scaled-down icon for the Toolbar.
    {
        TypedValue tv = new TypedValue();
        getTheme().resolveAttribute(R.attr.actionBarSize, tv, true);
        int height = TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics());
        // This originally used a scaled-down launcher icon, but I don't feel like figuring
        // out how to render R.mipmap.chromadoze_icon correctly.
        mToolbarIcon = ContextCompat.getDrawable(this, R.drawable.toolbar_icon);
    }

    // When this Activity is first created, set up the initial fragment.
    // After a save/restore, the framework will drop in the last-used
    // fragment automatically.
    if (savedInstanceState == null) {
        changeFragment(new MainFragment(), false);
    }
}