android.view.Display#getSize ( )源码实例Demo

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

protected void init(Context context, AttributeSet attributeSet) {
    mColorNormal = getColor(android.R.color.holo_blue_dark);
    mColorPressed = getColor(android.R.color.holo_blue_light);
    mIcon = 0;
    mSize = SIZE_NORMAL;
    if (attributeSet != null) {
        initAttributes(context, attributeSet);
    }

    mCircleSize = getCircleSize(mSize);
    mShadowRadius = getDimension(R.dimen.fab_shadow_radius);
    mShadowOffset = getDimension(R.dimen.fab_shadow_offset);
    mDrawableSize = (int) (mCircleSize + 2 * mShadowRadius);

    //point size overhead
    WindowManager mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = mWindowManager.getDefaultDisplay();
    Point size = new Point();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
        display.getSize(size);
        mYHidden = size.y;
    } else mYHidden = display.getHeight();

    updateBackground();
}
 
源代码2 项目: NightWatch   文件: BIGChart.java
@Override
public void onCreate() {
    super.onCreate();
    Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE))
            .getDefaultDisplay();
    display.getSize(displaySize);
    wakeLock = ((PowerManager) getSystemService(Context.POWER_SERVICE)).newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Clock");

    specW = View.MeasureSpec.makeMeasureSpec(displaySize.x,
            View.MeasureSpec.EXACTLY);
    specH = View.MeasureSpec.makeMeasureSpec(displaySize.y,
            View.MeasureSpec.EXACTLY);
    sharedPrefs = PreferenceManager
            .getDefaultSharedPreferences(this);
    sharedPrefs.registerOnSharedPreferenceChangeListener(this);
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    layoutView = inflater.inflate(R.layout.activity_bigchart, null);
    performViewSetup();
}
 
@Override public String getScreenResolution() {
  Context context = AppliverySdk.getApplicationContext();
  WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
  Display display = windowManager.getDefaultDisplay();

  int width;
  int height;
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
    Point size = new Point();
    display.getSize(size);
    width = size.x;
    height = size.y;
  } else {
    width = display.getWidth();
    height = display.getHeight();
  }

  String screenResolution = String.format(Locale.getDefault(), "%dx%d", width, height);

  return screenResolution;
}
 
源代码4 项目: Yahala-Messenger   文件: ChatActivity.java
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);


    setHasOptionsMenu(true);
    Display display = parentActivity.getWindowManager().getDefaultDisplay();
    if (android.os.Build.VERSION.SDK_INT < 13) {
        displaySize.set(display.getWidth(), display.getHeight());
    } else {
        display.getSize(displaySize);
    }


}
 
源代码5 项目: xDrip-Experimental   文件: CircleWatchface.java
@Override
public void onCreate() {
    super.onCreate();

    PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
    PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "CreateWakelock");
    wakeLock.acquire(30000);

    Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE))
            .getDefaultDisplay();
    display.getSize(displaySize);

    specW = View.MeasureSpec.makeMeasureSpec(displaySize.x,
            View.MeasureSpec.EXACTLY);
    specH = View.MeasureSpec.makeMeasureSpec(displaySize.y,
            View.MeasureSpec.EXACTLY);

    sharedPrefs = PreferenceManager
            .getDefaultSharedPreferences(this);
    sharedPrefs.registerOnSharedPreferenceChangeListener(this);

    //register Message Receiver
    LocalBroadcastManager.getInstance(this).registerReceiver(messageReceiver, new IntentFilter(Intent.ACTION_SEND));

    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    myLayout = inflater.inflate(R.layout.modern_layout, null);
    prepareLayout();
    prepareDrawTime();

    //ListenerService.requestData(this); //usually connection is not set up yet

    wakeLock.release();
}
 
源代码6 项目: CumulusTV   文件: Utils.java
/**
 * Returns the screen/display size
 */
public static Point getDisplaySize(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    return size;
}
 
源代码7 项目: LikeYahooWeather   文件: ImageUtils.java
/**
 * Get the screen width.
 * 
 * @param context
 * @return the screen width
 */
@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
public static int getScreenWidth(Activity context) {

	Display display = context.getWindowManager().getDefaultDisplay();
	if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
		Point size = new Point();
		display.getSize(size);
		return size.x;
	}
	return display.getWidth();
}
 
源代码8 项目: Vitamio-Cordova-Plugin   文件: VitamioMedia.java
private void fixMediaSize() {
    if (mMediaPlayer == null || !mIsMediaReadyToBePlayed)
        return;
    int width = mMediaPlayer.getVideoWidth();
    int height = mMediaPlayer.getVideoHeight();
    Display display = getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    int screenWidth = size.x;
    int screenHeight = size.y;
    android.view.ViewGroup.LayoutParams videoParams = mMediaView.getLayoutParams();

    if (width > 0 && height > 0) {
        Log.i(TAG, "Video is: " + width + " x " + height);

        if (width > height) {
            videoParams.width = screenWidth;
            videoParams.height = screenWidth * height / width;
        } else {
            videoParams.width = screenHeight * width / height;
            videoParams.height = screenHeight;
        }
    } else {
        videoParams.width = 0;
        videoParams.height = 0;
    }

    Log.i(TAG, "Setting dimensions to: " + videoParams.width + " x " + videoParams.height);
    mMediaView.setLayoutParams(videoParams);
}
 
源代码9 项目: BuildingForAndroidTV   文件: Utils.java
/**
 * Returns the screen/display size
 *
 * @param context
 * @return
 */
public static Point getDisplaySize(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    int width = size.x;
    int height = size.y;
    return new Point(width, height);
}
 
源代码10 项目: Mizuu   文件: MizLib.java
public static String getBackdropThumbUrlSize(Context c) {
    WindowManager window = (WindowManager) c.getSystemService(Context.WINDOW_SERVICE);
    Display d = window.getDefaultDisplay();

    Point size = new Point();
    d.getSize(size);

    final int width = Math.min(size.x, size.y);

    if (width >= 780)
        return "w780";
    if (width >= 400)
        return "w500";
    return "w300";
}
 
源代码11 项目: cannonball-android   文件: ThemeAdapter.java
private void setDisplaySize() {
    final WindowManager wm
            = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
    final Display display = wm.getDefaultDisplay();
    final Point p = new Point();
    display.getSize(p);
    final Float ht_px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
            HEADER_LAYOUT_HEIGHT, getContext().getResources().getDisplayMetrics());
    height = (p.y - ht_px.intValue()) / Theme.values().length;
    width = p.x;
}
 
源代码12 项目: KUAS-AP-Material   文件: Utils.java
public static Point getDisplayDimen(Context context) {
	Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE))
			.getDefaultDisplay();
	Point size = new Point();
	display.getSize(size);
	return size;
}
 
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int width = 0;
    int height = 0;

    Display display = mWindowManager.getDefaultDisplay();
    display.getSize(mSize);
    int displayWidth = mSize.x;
    int displayHeight = mSize.y;
    displayWidth = getWidth();
    displayHeight = getHeight();

    int widthSpecMode = MeasureSpec.getMode(widthMeasureSpec);
    int widthSpecSize = MeasureSpec.getSize(widthMeasureSpec);
    int heightSpecMode = MeasureSpec.getMode(heightMeasureSpec);
    int heightSpecSize = MeasureSpec.getSize(heightMeasureSpec);
    Log.d(TAG, "widthSpecSize=" + widthSpecSize + ", heightSpecSize=" + heightSpecSize);

    if (widthSpecMode == MeasureSpec.EXACTLY) {
        width = widthSpecSize;
    } else if (widthSpecMode == MeasureSpec.AT_MOST) {
        width = Math.min(displayWidth, widthSpecSize);
    } else {
        width = displayWidth;
    }

    if (heightSpecMode == MeasureSpec.EXACTLY) {
        height = heightSpecSize;
    } else if (heightSpecMode == MeasureSpec.AT_MOST) {
        height = Math.min(displayHeight, heightSpecSize);
    } else {
        height = displayHeight;
    }

    setMeasuredDimension(width, height);

    if (width > 0 && height > 0) {
        loadBitmaps(width, height);
    }
}
 
源代码14 项目: Mizuu   文件: MizLib.java
public static int getDisplaySize(Context c, int type) {
    WindowManager wm = (WindowManager) c.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();

    Point size = new Point();
    display.getSize(size);

    return type == HEIGHT ?
            size.y : size.x;
}
 
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Display display = getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);

    mPongGame = new PongGame(this, size.x, size.y);
    setContentView(mPongGame);
}
 
源代码16 项目: AirPanel   文件: Helper.java
@Override
public void setup(Activity activity) {
    mRootView = activity.getWindow().getDecorView();
    // Get DisplayHeight
    WindowManager windowManager = (WindowManager) activity.getSystemService(Context.WINDOW_SERVICE);
    Display display = windowManager.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    mDisplayHeight = size.y;
    Util.log("setup mDisplayHeight:%s point:%s", mDisplayHeight, size.toString());
}
 
源代码17 项目: kakao-android-sdk-standalone   文件: SystemInfo.java
@TargetApi(13)
private static Point getSize(Display display) {
    Point point = new Point();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
        display.getSize(point);
    } else {
        point.set(display.getWidth(), display.getHeight());
    }
    return point;
}
 
源代码18 项目: android-login   文件: LoginActivity.java
private int[] screenSize() {
  Display display = getWindowManager().getDefaultDisplay();
  Point size = new Point();
  display.getSize(size);
  return new int[]{size.x, size.y};
}
 
源代码19 项目: mobile-sdk-android   文件: BannerAdView.java
@SuppressLint("NewApi")
@SuppressWarnings("deprecation")
protected void expandToFitScreenWidth(int adWidth, int adHeight,  View view) {
    //Determine the width of the screen
    WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();

    @SuppressWarnings("UnusedAssignment") int width = -1;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
        Point p = new Point();
        display.getSize(p);
        width = p.x;
    } else {
        width = display.getWidth();
    }

    float ratio_delta = ((float) width) / ((float) adWidth);
    int new_height = (int) Math.floor(adHeight * ratio_delta);
    if(getLayoutParams() != null) {
        oldH = getLayoutParams().height;
        oldW = getLayoutParams().width;

        //Adjust width of container
        if (getLayoutParams().width > 0 || getLayoutParams().width == ViewGroup.LayoutParams.WRAP_CONTENT) {
            getLayoutParams().width = width;
        }

        //Adjust height of container
        getLayoutParams().height = new_height;
    }

    if(view instanceof WebView) {

        //Adjust height of webview
        if (view.getLayoutParams() == null) {
            view.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT));
        } else {
            view.getLayoutParams().width = FrameLayout.LayoutParams.MATCH_PARENT;
            view.getLayoutParams().height = FrameLayout.LayoutParams.MATCH_PARENT;
        }
        ((WebView)view).setInitialScale((int) Math.ceil(ratio_delta * 100));
    }else{
        int adWidthInPixel = ViewUtil.getValueInPixel(getContext(), adWidth);
        float widthRatio = (float) width / (float) adWidthInPixel;
        view.setScaleX(widthRatio);
        view.setScaleY(widthRatio);
    }
    view.invalidate();
    shouldResetContainer = true;

}
 
源代码20 项目: smartcoins-wallet   文件: eReceipt.java
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.e_receipt);
        ButterKnife.bind(this);

        // Instantiating the database
        database = new SCWallDatabase(this);

        // Retrieving the currently active account from the legacy tinyDB implementation
        tinyDB = new TinyDB(this);
        ArrayList<AccountDetails> accountDetails = tinyDB.getListObject(getString(R.string.pref_wallet_accounts), AccountDetails.class);
        for (AccountDetails accountDetail : accountDetails) {
            if (accountDetail.isSelected) {
                user = database.fillUserDetails(new UserAccount(accountDetail.account_id));
            }
        }

        // Deserializing the HistoricalTransferEntry object, which contains all
        // detailed information about this transfer.
        Gson gson = new Gson();
        String jsonOperation = getIntent().getExtras().getString(TableViewClickListener.KEY_OPERATION_ENTRY);
        historicalTransferEntry = gson.fromJson(jsonOperation, HistoricalTransferEntry.class);

        // Setting the memo message
        TransferOperation transfer = historicalTransferEntry.getHistoricalTransfer().getOperation();
        memo.setText(String.format(memo.getText().toString(), transfer.getMemo().getPlaintextMessage()));

        transactionId = historicalTransferEntry.getHistoricalTransfer().getId();

        progressDialog = new ProgressDialog(this);
        Application.registerBalancesDelegateEReceipt(this);
        setTitle(getResources().getString(R.string.e_receipt_activity_name));
        hideProgressBar();
        Intent intent = getIntent();
        String eReciept = intent.getStringExtra(getResources().getString(R.string.e_receipt));

        memoMsg = intent.getStringExtra("Memo");
        date = intent.getStringExtra("Date");
        time = intent.getStringExtra("Time");
        timeZone = intent.getStringExtra("TimeZone");

        UserAccount fromUser = historicalTransferEntry.getHistoricalTransfer().getOperation().getFrom();
        UserAccount toUser = historicalTransferEntry.getHistoricalTransfer().getOperation().getTo();
        if (fromUser.getObjectId().equals(user.getObjectId())) {
            ivImageTag.setImageResource(R.drawable.send);
            tvUserStatus.setText(getString(R.string.sender_account));
            tvOtherStatus.setText(getString(R.string.receiver_account));
            otherName = toUser.getName();
            userName = fromUser.getName();
        } else {
            tvUserStatus.setText(getString(R.string.receiver_account));
            tvOtherStatus.setText(getString(R.string.sender_account));
            ivImageTag.setImageResource(R.drawable.receive);
            otherName = fromUser.getName();
            userName = toUser.getName();
        }

        tvOtherName.setText(otherName);
        tvUserName.setText(userName);
//        TvBlockNum.setText(date);
        tvTime.setText(time + " " + timeZone);

        Display display = getWindowManager().getDefaultDisplay();
        Point size = new Point();
        display.getSize(size);
        int width = size.x;

        ivOtherGravatar.requestLayout();

        ivOtherGravatar.getLayoutParams().height = (width * 40) / 100;
        ivOtherGravatar.getLayoutParams().width = (width * 40) / 100;


        fetchGravatarInfo(get_email(otherName));

        setBackButton(true);

        HistoricalTransfer historicalTransfer = historicalTransferEntry.getHistoricalTransfer();
        tvBlockNumber.setText(String.format("%d", historicalTransfer.getBlockNum()));
        tvTrxInBlock.setText(String.format("%s", historicalTransfer.getId()));

        double amount = Util.fromBase(historicalTransfer.getOperation().getAssetAmount());
        String symbol = historicalTransfer.getOperation().getAssetAmount().getAsset().getSymbol();
        int precision = historicalTransfer.getOperation().getAssetAmount().getAsset().getPrecision();
        String textFormat = String.format("%%.%df %%s", precision);
        tvPaymentAmount.setText(String.format(textFormat, amount, symbol));

        if (historicalTransferEntry.getEquivalentValue() != null) {
            double eqValueAmount = Util.fromBase(historicalTransferEntry.getEquivalentValue());
            String eqValueSymbol = historicalTransferEntry.getEquivalentValue().getAsset().getSymbol();
            tvPaymentEquivalent.setText(String.format("%.2f %s", eqValueAmount, eqValueSymbol));
        }
    }