Example usage for android.view WindowManager getDefaultDisplay

List of usage examples for android.view WindowManager getDefaultDisplay

Introduction

In this page you can find the example usage for android.view WindowManager getDefaultDisplay.

Prototype

public Display getDefaultDisplay();

Source Link

Document

Returns the Display upon which this WindowManager instance will create new windows.

Usage

From source file:androidx.media.widget.MediaControlView2.java

@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    // Update layout when this view's width changes in order to avoid any UI overlap between
    // transport controls.
    if (mPrevWidth != getMeasuredWidth() || mPrevHeight != getMeasuredHeight() || mNeedUXUpdate) {
        // Dismiss SettingsWindow if it is showing.
        mSettingsWindow.dismiss();/*from  ww  w  .  j  av a 2s .  c  om*/

        // These views may not have been initialized yet.
        if (mTransportControls.getWidth() == 0 || mTimeView.getWidth() == 0) {
            return;
        }

        int currWidth = getMeasuredWidth();
        int currHeight = getMeasuredHeight();
        WindowManager manager = (WindowManager) getContext().getApplicationContext()
                .getSystemService(Context.WINDOW_SERVICE);
        Point screenSize = new Point();
        manager.getDefaultDisplay().getSize(screenSize);
        int screenWidth = screenSize.x;
        int screenHeight = screenSize.y;
        int fullIconSize = mResources.getDimensionPixelSize(R.dimen.mcv2_full_icon_size);
        int embeddedIconSize = mResources.getDimensionPixelSize(R.dimen.mcv2_embedded_icon_size);
        int marginSize = mResources.getDimensionPixelSize(R.dimen.mcv2_icon_margin);

        // TODO: add support for Advertisement Mode.
        if (mMediaType == MEDIA_TYPE_DEFAULT) {
            // Max number of icons inside BottomBarRightView for Music mode is 4.
            int maxIconCount = 4;
            updateLayout(maxIconCount, fullIconSize, embeddedIconSize, marginSize, currWidth, currHeight,
                    screenWidth, screenHeight);

        } else if (mMediaType == MEDIA_TYPE_MUSIC) {
            if (mNeedUXUpdate) {
                // One-time operation for Music media type
                mBasicControls.removeView(mMuteButton);
                mExtraControls.addView(mMuteButton, 0);
                mVideoQualityButton.setVisibility(View.GONE);
                if (mFfwdButton != null) {
                    mFfwdButton.setVisibility(View.GONE);
                }
                if (mRewButton != null) {
                    mRewButton.setVisibility(View.GONE);
                }
            }
            mNeedUXUpdate = false;

            // Max number of icons inside BottomBarRightView for Music mode is 3.
            int maxIconCount = 3;
            updateLayout(maxIconCount, fullIconSize, embeddedIconSize, marginSize, currWidth, currHeight,
                    screenWidth, screenHeight);
        }
        mPrevWidth = currWidth;
        mPrevHeight = currHeight;
    }
    // TODO: move this to a different location.
    // Update title bar parameters in order to avoid overlap between title view and the right
    // side of the title bar.
    updateTitleBarLayout();
}

From source file:com.efithealth.app.activity.ChatActivity.java

/**
 * initView/*from ww  w.  ja v  a  2 s  . co m*/
 */
protected void initView() {
    panel_root = (KPSwitchFSPanelLinearLayout) findViewById(R.id.panel_root);

    //? 
    ogll = new OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
            Rect rect = new Rect();

            getWindow().getDecorView().getWindowVisibleDisplayFrame(rect);
            WindowManager wm = getWindowManager();
            height = wm.getDefaultDisplay().getHeight();

            int h = height - (rect.bottom - rect.top);
            boolean flag123 = h > height / 3;
            if (flag123) {
                panel_root.setVisibility(View.VISIBLE);
            } else {
                panel_root.setVisibility(View.GONE);
            }

        }
    };

    recordingContainer = findViewById(R.id.recording_container);
    micImage = (ImageView) findViewById(R.id.mic_image);
    recordingHint = (TextView) findViewById(R.id.recording_hint);
    listView = (ListView) findViewById(R.id.list);
    mEditTextContent = (PasteEditText) findViewById(R.id.et_sendmessage);
    buttonSetModeKeyboard = findViewById(R.id.btn_set_mode_keyboard);
    edittext_layout = (RelativeLayout) findViewById(R.id.edittext_layout);
    buttonSetModeVoice = findViewById(R.id.btn_set_mode_voice);
    buttonSend = findViewById(R.id.btn_send);
    buttonPressToSpeak = findViewById(R.id.btn_press_to_speak);
    expressionViewpager = (ViewPager) findViewById(R.id.vPager);
    emojiIconContainer = (LinearLayout) findViewById(R.id.ll_face_container);
    btnContainer = (LinearLayout) findViewById(R.id.ll_btn_container);
    locationImgview = (ImageView) findViewById(R.id.btn_location);
    iv_emoticons_normal = (ImageView) findViewById(R.id.iv_emoticons_normal);
    iv_emoticons_checked = (ImageView) findViewById(R.id.iv_emoticons_checked);
    loadmorePB = (ProgressBar) findViewById(R.id.pb_load_more);
    btnMore = (Button) findViewById(R.id.btn_more);
    iv_emoticons_normal.setVisibility(View.VISIBLE);
    iv_emoticons_checked.setVisibility(View.INVISIBLE);
    more = findViewById(R.id.more);
    edittext_layout.setBackgroundResource(R.drawable.input_bar_bg_normal);
    voiceCallBtn = (ImageView) findViewById(R.id.btn_voice_call);
    videoCallBtn = (ImageView) findViewById(R.id.btn_video_call);
    findViewById(R.id.container_voice_call).setVisibility(View.GONE);
    findViewById(R.id.container_video_call).setVisibility(View.GONE);
    findViewById(R.id.container_file).setVisibility(View.GONE);
    // ?,
    micImages = new Drawable[] { getResources().getDrawable(R.drawable.record_animate_01),
            getResources().getDrawable(R.drawable.record_animate_02),
            getResources().getDrawable(R.drawable.record_animate_03),
            getResources().getDrawable(R.drawable.record_animate_04),
            getResources().getDrawable(R.drawable.record_animate_05),
            getResources().getDrawable(R.drawable.record_animate_06),
            getResources().getDrawable(R.drawable.record_animate_07),
            getResources().getDrawable(R.drawable.record_animate_08),
            getResources().getDrawable(R.drawable.record_animate_09),
            getResources().getDrawable(R.drawable.record_animate_10),
            getResources().getDrawable(R.drawable.record_animate_11),
            getResources().getDrawable(R.drawable.record_animate_12),
            getResources().getDrawable(R.drawable.record_animate_13),
            getResources().getDrawable(R.drawable.record_animate_14) };

    // list
    reslist = getExpressionRes(35);
    // ?viewpager
    List<View> views = new ArrayList<View>();
    View gv1 = getGridChildView(1);
    View gv2 = getGridChildView(2);
    views.add(gv1);
    views.add(gv2);
    expressionViewpager.setAdapter(new ExpressionPagerAdapter(views));
    edittext_layout.requestFocus();
    voiceRecorder = new VoiceRecorder(micImageHandler);
    buttonPressToSpeak.setOnTouchListener(new PressToSpeakListen());
    mEditTextContent.setOnFocusChangeListener(new OnFocusChangeListener() {

        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
                edittext_layout.setBackgroundResource(R.drawable.input_bar_bg_active);
            } else {
                edittext_layout.setBackgroundResource(R.drawable.input_bar_bg_normal);
            }

        }
    });
    mEditTextContent.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            //??
            getWindow().getDecorView().getViewTreeObserver().addOnGlobalLayoutListener(ogll);

            edittext_layout.setBackgroundResource(R.drawable.input_bar_bg_active);
            more.setVisibility(View.GONE);
            iv_emoticons_normal.setVisibility(View.VISIBLE);
            iv_emoticons_checked.setVisibility(View.INVISIBLE);
            emojiIconContainer.setVisibility(View.GONE);
            btnContainer.setVisibility(View.GONE);
        }
    });
    // ?
    mEditTextContent.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (!TextUtils.isEmpty(s)) {
                btnMore.setVisibility(View.GONE);
                buttonSend.setVisibility(View.VISIBLE);
            } else {
                btnMore.setVisibility(View.VISIBLE);
                buttonSend.setVisibility(View.GONE);
            }
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void afterTextChanged(Editable s) {

        }
    });

    swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.chat_swipe_layout);

    swipeRefreshLayout.setColorScheme(android.R.color.holo_blue_bright, android.R.color.holo_green_light,
            android.R.color.holo_orange_light, android.R.color.holo_red_light);

    swipeRefreshLayout.setOnRefreshListener(new OnRefreshListener() {

        @Override
        public void onRefresh() {
            new Handler().postDelayed(new Runnable() {

                @Override
                public void run() {
                    if (listView.getFirstVisiblePosition() == 0 && !isloading && haveMoreData) {
                        List<EMMessage> messages;
                        try {
                            if (chatType == CHATTYPE_SINGLE) {
                                messages = conversation.loadMoreMsgFromDB(adapter.getItem(0).getMsgId(),
                                        pagesize);
                            } else {
                                messages = conversation.loadMoreGroupMsgFromDB(adapter.getItem(0).getMsgId(),
                                        pagesize);
                            }
                        } catch (Exception e1) {
                            swipeRefreshLayout.setRefreshing(false);
                            return;
                        }

                        if (messages.size() > 0) {
                            adapter.notifyDataSetChanged();
                            adapter.refreshSeekTo(messages.size() - 1);
                            if (messages.size() != pagesize) {
                                haveMoreData = false;
                            }
                        } else {
                            haveMoreData = false;
                        }

                        isloading = false;

                    } else {
                        Toast.makeText(ChatActivity.this, getResources().getString(R.string.no_more_messages),
                                Toast.LENGTH_SHORT).show();
                    }
                    swipeRefreshLayout.setRefreshing(false);
                }
            }, 1000);
        }
    });
}

From source file:es.javocsoft.android.lib.toolbox.ToolBox.java

/**
 * Returns the device resolution type./*from   w  w w .  ja  v  a  2s.  c om*/
 * 
 * @param context
 * @return   {@link es.javocsoft.android.lib.toolbox.ToolBox.DEVICE_RESOLUTION_TYPE}
 */
public static DEVICE_RESOLUTION_TYPE device_getResolutionType(Context context) {
    DEVICE_RESOLUTION_TYPE res = null;

    DisplayMetrics metrics = new DisplayMetrics();
    WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    windowManager.getDefaultDisplay().getMetrics(metrics);

    switch (metrics.densityDpi) {
    case DisplayMetrics.DENSITY_LOW:
        res = DEVICE_RESOLUTION_TYPE.ldpi;
        break;
    case DisplayMetrics.DENSITY_MEDIUM:
        res = DEVICE_RESOLUTION_TYPE.mdpi;
        break;
    case DisplayMetrics.DENSITY_HIGH:
        res = DEVICE_RESOLUTION_TYPE.hdpi;
        break;
    case DisplayMetrics.DENSITY_XHIGH:
        res = DEVICE_RESOLUTION_TYPE.xhdpi;
        break;
    case DisplayMetrics.DENSITY_XXHIGH:
        res = DEVICE_RESOLUTION_TYPE.xxhdpi;
        break;
    }

    return res;
}

From source file:com.fullteem.yueba.app.ui.ChatActivity.java

/**
 * window//from www.  ja  va 2s.c om
 */
private void windowShow() {
    if (popupWindow == null) {
        LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        menuView = layoutInflater.inflate(R.layout.popwindow_msgmenu, null);
        listviewMsgMenus = (ListView) menuView.findViewById(R.id.listviewMsgPop);
        mma = new MessageMenuAdapter(this, menuTexts);
        listviewMsgMenus.setAdapter(mma);
        // PopuWidow
        popupWindow = new PopupWindow(menuView, 300, 500);
    }

    // ?
    popupWindow.setFocusable(true);
    // ?
    popupWindow.setOutsideTouchable(true);

    // Back???
    popupWindow.setBackgroundDrawable(new BitmapDrawable());
    WindowManager windowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
    // ?:??-PopupWindow?
    int xPos = windowManager.getDefaultDisplay().getWidth() / 2 - popupWindow.getWidth() / 2;

    Log.i("coder", "windowManager.getDefaultDisplay().getWidth()/2:"
            + windowManager.getDefaultDisplay().getWidth() / 2);
    //
    Log.i("coder", "popupWindow.getWidth()/2:" + popupWindow.getWidth() / 2);

    Log.i("coder", "xPos:" + xPos);

    popupWindow.showAsDropDown(viewBtnMore, xPos, 0);
    listviewMsgMenus.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {

            if (popupWindow != null) {
                popupWindow.dismiss();
            }

            // 
            if (menuTexts[position].equals("")) {
                String strName = getString(R.string.add_firend);
                String msg = String.format(strName, userNickName);
                popMenu = new CommonPopWindow(ChatActivity.this, msg, new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        addContact();
                        addFriendPop.dismiss();
                    }
                }, new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        addFriendPop.dismiss();
                    }
                });

                // ?
                popMenu.setIsEditText(false);

                // 
                popMenu.preperShow();
                addFriendPop = popMenu.getMenu();
                addFriendPop.setOutsideTouchable(true);
                if (addFriendPop == null) {
                    return;
                }

                if (addFriendPop.isShowing()) {
                    addFriendPop.dismiss();
                    return;
                }
                addFriendPop.showAtLocation(getWindow().getDecorView(), Gravity.CENTER, 0, 0);

            } else if (menuTexts[position].equals("?")) {

            }

            // ?
            else if (menuTexts[position].equals("")) {
                // try {
                // EMContactManager.getInstance().deleteContact(
                // toChatUsername);
                // } catch (EaseMobException e) {
                // showToast("");
                // }
                deleteFriends();

            } else if (menuTexts[position].equals("?")) {// bill
                Intent intentDatePublish = new Intent(ChatActivity.this, DatePublishActivity.class);
                // TODO ????id,????????idname
                DBFriendListDao friendListDao = new DBFriendListDao(ChatActivity.this);
                UserCommonModel um = friendListDao.getContacter(toChatUsername);
                if (um == null)
                    return;
                UmengUtil.onEvent(ChatActivity.this, "friend_chat_access_post_date_button_hits");
                LogUtil.printUmengLog("friend_chat_access_post_date_button_hits");
                intentDatePublish.putExtra(GlobleConstant.DATE_FAVORITE_ID,
                        Integer.valueOf(TextUtils.isEmpty(um.getUserId()) ? "0" : um.getUserId())); // userIdint
                intentDatePublish.putExtra(GlobleConstant.DATE_FAVORITE_NAME, um.getUserName()); // String
                intentDatePublish.putExtra(GlobleConstant.DATE_FAVORITE_MOBILE, um.getUserMobile());
                intentDatePublish.putExtra(GlobleConstant.DATE_FAVORITE_URL, um.getUserLogoUrl());
                intentDatePublish.putExtra("isExist", true);
                startActivity(intentDatePublish);
            } else if (menuTexts[position].equals("")) {
                HttpRequest.getInstance(ChatActivity.this).getOutGroup(appContext.getUserInfo().getUserMobile(),
                        toChatUsername, new CustomAsyncResponehandler() {

                            @Override
                            public void onSuccess(ResponeModel baseModel) {
                                if (baseModel != null && baseModel.isStatus()) {
                                    showToast("?");
                                    finish();
                                    return;
                                }
                                showToast(getString(R.string.hint_operationError));
                            }

                            @Override
                            public void onFailure(Throwable error, String content) {
                                showToast(getString(R.string.hint_operationError));
                            }
                        });
            }
        }

    });

}

From source file:com.androzic.Androzic.java

public void onCreateEx() {
    try {/*from  w  w w  .  j  a  v a 2s. c  o  m*/
        (new File(Environment.getExternalStorageDirectory(), WordManager.FOLDER)).mkdirs();
        (new File(Environment.getExternalStorageDirectory(), WordManager.FOLDER + "/ghiam")).mkdirs();
    } catch (Throwable e) {
    }

    if (initialized)
        return;

    AndroidGraphicFactory.createInstance(this);
    try {
        OzfDecoder.useNativeCalls();
    } catch (UnsatisfiedLinkError e) {
        Toast.makeText(Androzic.this, "Failed to initialize native library: " + e.getMessage(),
                Toast.LENGTH_LONG).show();
    }

    Resources resources = getResources();
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
    Configuration config = resources.getConfiguration();

    renderingThread = new HandlerThread("RenderingThread");
    renderingThread.start();

    longOperationsThread = new HandlerThread("LongOperationsThread");
    longOperationsThread.setPriority(Thread.MIN_PRIORITY);
    longOperationsThread.start();

    uiHandler = new Handler();
    mapsHandler = new Handler(longOperationsThread.getLooper());

    // We silently initialize data uri to let location service restart after crash
    File datadir = new File(
            settings.getString(getString(R.string.pref_folder_data), Environment.getExternalStorageDirectory()
                    + File.separator + resources.getString(R.string.def_folder_data)));
    setDataPath(Androzic.PATH_DATA, datadir.getAbsolutePath());

    setInstance(this);

    String intentToCheck = "com.androzic.donate";
    String myPackageName = getPackageName();
    PackageManager pm = getPackageManager();
    PackageInfo pi;
    try {
        pi = pm.getPackageInfo(intentToCheck, 0);
        isPaid = (pm.checkSignatures(myPackageName, pi.packageName) == PackageManager.SIGNATURE_MATCH);
    } catch (NameNotFoundException e) {
        //         e.printStackTrace();
    }

    File sdcard = Environment.getExternalStorageDirectory();
    Thread.setDefaultUncaughtExceptionHandler(new CrashHandler(this, sdcard.getAbsolutePath()));

    DisplayMetrics displayMetrics = new DisplayMetrics();

    WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
    if (wm != null) {
        wm.getDefaultDisplay().getMetrics(displayMetrics);
    } else {
        displayMetrics.setTo(resources.getDisplayMetrics());
    }
    BaseMap.viewportWidth = displayMetrics.widthPixels;
    BaseMap.viewportHeight = displayMetrics.heightPixels;

    charset = settings.getString(getString(R.string.pref_charset), "UTF-8");
    String lang = settings.getString(getString(R.string.pref_locale), "");
    if (!"".equals(lang) && !config.locale.getLanguage().equals(lang)) {
        locale = new Locale(lang);
        Locale.setDefault(locale);
        config.locale = locale;
        resources.updateConfiguration(config, resources.getDisplayMetrics());
    }

    magInterval = resources.getInteger(R.integer.def_maginterval) * 1000;

    overlayManager = new OverlayManager(longOperationsThread.getLooper());
    TooltipManager.initialize(this);

    onSharedPreferenceChanged(settings, getString(R.string.pref_unitcoordinate));
    onSharedPreferenceChanged(settings, getString(R.string.pref_unitdistance));
    onSharedPreferenceChanged(settings, getString(R.string.pref_unitspeed));
    onSharedPreferenceChanged(settings, getString(R.string.pref_unitelevation));
    onSharedPreferenceChanged(settings, getString(R.string.pref_unitangle));
    onSharedPreferenceChanged(settings, getString(R.string.pref_unitanglemagnetic));
    onSharedPreferenceChanged(settings, getString(R.string.pref_unitprecision));
    onSharedPreferenceChanged(settings, getString(R.string.pref_unitsunrise));
    onSharedPreferenceChanged(settings, getString(R.string.pref_mapadjacent));
    onSharedPreferenceChanged(settings, getString(R.string.pref_vectormap_textscale));
    onSharedPreferenceChanged(settings, getString(R.string.pref_onlinemapprescalefactor));
    onSharedPreferenceChanged(settings, getString(R.string.pref_onlinemapexpiration));
    onSharedPreferenceChanged(settings, getString(R.string.pref_mapcropborder));
    onSharedPreferenceChanged(settings, getString(R.string.pref_mapdrawborder));
    onSharedPreferenceChanged(settings, getString(R.string.pref_showwaypoints));
    onSharedPreferenceChanged(settings, getString(R.string.pref_showcurrenttrack));
    onSharedPreferenceChanged(settings, getString(R.string.pref_showaccuracy));
    onSharedPreferenceChanged(settings, getString(R.string.pref_showdistance_int));

    settings.registerOnSharedPreferenceChangeListener(this);

    initialized = true;
}

From source file:com.bookkos.bircle.CaptureActivity.java

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    _context = getApplicationContext();/*w ww. j  a v a 2  s. c  om*/
    _activity = this;

    currentTime = new Time("Asia/Tokyo");

    //      exceptionHandler = new ExceptionHandler(_context);   
    //      Thread.setDefaultUncaughtExceptionHandler(exceptionHandler);

    // sharedPreference???, user_id?group_id?registration_id??
    getUserData();

    Window window = getWindow();
    window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    // ??
    WindowManager window_manager = getWindowManager();
    Display display = window_manager.getDefaultDisplay();
    Point point = new Point();
    display.getSize(point);
    displayWidth = point.x;
    displayHeight = point.y;

    displayInch = getInch();
    // ??4???????
    textSize = 17 * (displayInch / 4);

    actionBar = getActionBar();
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE, ActionBar.DISPLAY_USE_LOGO);
    actionBar.setDisplayShowTitleEnabled(true);
    actionBar.setDisplayUseLogoEnabled(false);
    actionBar.setDisplayShowHomeEnabled(false);
    actionBar.setDisplayHomeAsUpEnabled(false);
    String title_text = "";
    subGroupText = "";
    groupText = groupName;

    if (displayInch < 4.7) {
        title_text = "<small><small><small>??: </small></small></small>";
        resizeTitleSizeTooSmall();
    } else if (displayInch >= 4.7 && displayInch < 5.5) {
        title_text = "<small><small>??: </small></small>";
        resizeTitleSizeSmall();
    } else if (displayInch >= 5.5 && displayInch < 6.5) {
        title_text = "<small>??: </small>";
        resizeTitleSizeMiddle();
    } else if (displayInch >= 6.5 && displayInch < 8) {
        title_text = "<small>??: </small>";
        resizeTitleSizeLarge();
    } else {
        title_text = "??: ";
    }
    String modify_group_text = title_text + "<font color=#FF0000>" + groupName + "</font>";
    actionBar.setTitle(Html.fromHtml(modify_group_text));

    Resources resources = _context.getResources();
    int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
    titleBarHeight = resources.getDimensionPixelSize(resourceId);

    setContentView(R.layout.capture);

    returnBorrowHelpView = (ImageView) findViewById(R.id.return_borrow_help_view);
    returnBorrowHelpView.setImageResource(R.drawable.return_borrow_help);
    returnBorrowHelpView.setTranslationY(displayHeight / 5 + titleBarHeight);
    returnBorrowHelpView.setLayoutParams(new FrameLayout.LayoutParams(displayWidth,
            displayHeight / 5 + titleBarHeight, Gravity.BOTTOM | Gravity.CENTER));

    registHelpView = (ImageView) findViewById(R.id.regist_help_view);
    registHelpView.setImageResource(R.drawable.regist_help);
    registHelpView.setTranslationY(displayHeight / 5 + titleBarHeight);
    registHelpView.setLayoutParams(new FrameLayout.LayoutParams(displayWidth,
            displayHeight / 5 + titleBarHeight, Gravity.BOTTOM | Gravity.CENTER));
    registHelpView.setVisibility(View.GONE);

    leftDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    leftDrawer = (ListView) findViewById(R.id.left_drawer);
    textView = (TextView) findViewById(R.id.textView);

    modeText = (TextView) findViewById(R.id.mode_text);
    modeText.setTextColor(Color.rgb(56, 234, 123));
    modeText.setTextSize(textSize);
    modeText.setTypeface(Typeface.SERIF.MONOSPACE, Typeface.BOLD);
    strokeColor = Color.rgb(56, 234, 123);

    borrowReturnButton = (Button) findViewById(R.id.borrowReturnButton);
    registButton = (Button) findViewById(R.id.registButton);
    returnHistoryButton = (Button) findViewById(R.id.return_history_button);
    helpViewButton = (Button) findViewById(R.id.help_view_button);

    registSelectShelfRelativeLayout = (RelativeLayout) findViewById(R.id.regist_select_shelf_relative_layout);
    textViewLinearLayout = (LinearLayout) findViewById(R.id.text_view_linear_layout);
    buttonLinearLayout = (LinearLayout) findViewById(R.id.button_linear_layout);
    listViewLinearLayout = (LinearLayout) findViewById(R.id.list_view_linear_layout);
    decisionButton = (Button) findViewById(R.id.decision_button);
    cancelButton = (Button) findViewById(R.id.cancel_button);
    shelfListView = (ListView) findViewById(R.id.shelf_list_view);
    tempTextView = (TextView) findViewById(R.id.temp_text_view);
    //      bookListViewAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1);
    bookListViewAdapter = new BookListViewAdapter(_context, R.layout.book_list_row, this);

    bookRegistRelativeLayout = (RelativeLayout) findViewById(R.id.book_regist_relative_layout);
    bookRegistLinearLayout = (LinearLayout) findViewById(R.id.book_regist_linear_layout);
    bookRegistListViewLinearLayout = (LinearLayout) findViewById(R.id.book_regist_list_view_linear_layout);
    bookRegistListView = (ListView) findViewById(R.id.book_regist_list_view);
    bookRegistTextView = (TextView) findViewById(R.id.book_regist_text_view);
    bookRegistCancelButton = (Button) findViewById(R.id.book_regist_cancel_button);

    registFlag = 0;

    int borrowReturnButton_width = displayWidth / 5 * 2;
    int borrowReturnButton_height = displayHeight / 10;
    int borrowReturnButton_x = ((displayWidth / 2) - borrowReturnButton_width) / 2;
    int borrowReturnButton_y = displayHeight / 2 + titleBarHeight;
    borrowReturnButton.setTranslationX(borrowReturnButton_x);
    borrowReturnButton.setTranslationY(borrowReturnButton_y);
    borrowReturnButton
            .setLayoutParams(new FrameLayout.LayoutParams(borrowReturnButton_width, borrowReturnButton_height));
    borrowReturnButton.setBackgroundColor(Color.rgb(56, 234, 123));
    borrowReturnButton.setText("??\n");
    borrowReturnButton.setTextSize(textSize * 7 / 10);
    borrowReturnButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            arrayList.clear();
            registFlag = 0;

            borrowReturnButton.setText("??\n");
            borrowReturnButton.setEnabled(false);
            borrowReturnButton.setTextColor(Color.WHITE);
            borrowReturnButton.setBackgroundColor(Color.rgb(56, 234, 123));

            registButton.setText("?\n??");
            registButton.setEnabled(true);
            registButton.setTextColor(Color.GRAY);
            registButton.setBackgroundColor(Color.argb(170, 21, 38, 45));

            modeText.setText("??");
            modeText.setTextColor(Color.rgb(56, 234, 123));
            returnBorrowHelpView.setVisibility(View.VISIBLE);
            registHelpView.setVisibility(View.GONE);
            strokeColor = Color.rgb(56, 234, 123);
        }
    });

    int registButton_width = displayWidth / 5 * 2;
    int registButton_height = displayHeight / 10;
    int registButton_x = (displayWidth / 2) + ((displayWidth / 2) - registButton_width) / 2;
    int registButton_y = displayHeight / 2 + titleBarHeight;
    registButton.setTranslationX(registButton_x);
    registButton.setTranslationY(registButton_y);
    registButton.setLayoutParams(new FrameLayout.LayoutParams(registButton_width, registButton_height));
    registButton.setBackgroundColor(Color.argb(170, 21, 38, 45));
    registButton.setTextColor(Color.GRAY);
    registButton.setTextSize(textSize * 7 / 10);
    registButton.setText("?\n??");
    registButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            arrayList.clear();
            registFlag = 1;

            borrowReturnButton.setText("??\n??");
            borrowReturnButton.setEnabled(true);
            borrowReturnButton.setTextColor(Color.GRAY);
            borrowReturnButton.setBackgroundColor(Color.argb(170, 9, 54, 16));

            registButton.setText("?\n");
            registButton.setEnabled(false);
            registButton.setTextColor(Color.WHITE);
            registButton.setBackgroundColor(Color.rgb(62, 162, 229));

            modeText.setText("?");
            modeText.setTextColor(Color.rgb(62, 162, 229));
            returnBorrowHelpView.setVisibility(View.GONE);
            registHelpView.setVisibility(View.VISIBLE);
            strokeColor = Color.rgb(62, 162, 229);
        }
    });

    returnHistoryButton.setText("????");
    returnHistoryButton.setTextSize(textSize * 7 / 10);
    returnHistoryButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            leftDrawerLayout.openDrawer(Gravity.RIGHT);
            //            animateTranslationY(bookRegistRelativeLayout, displayHeight, displayHeight - displayHeight / 4 - titleBarHeight);
        }
    });
    getReturnHistory();
    getCurrentTime();

    setHelpView();
    setScanUnregisterBookView();
    setBookRegistView();

    arrayList = new ArrayList<String>();
    tempRegistIsbn = "";

    initBookRegistUrl = book_register_url + "?user_id=" + userId + "&group_id=" + groupId;
    initLendRegistUrl = lend_register_url + "?user_id=" + userId + "&group_id=" + groupId;
    initTemporaryLendRegistUrl = temporary_lend_register_url + "?user_id=" + userId + "&group_id=" + groupId;
    initCatalogRegistUrl = catalog_register_url + "?group_id=" + groupId + "&book_code=";
    initManuallyCatalogRegistUrl = manually_catalog_register_url + "?group_id=" + groupId + "&book_code=";
    getStatusUrl = get_status_url + "?group_id=" + groupId + "&user_id=" + userId;

    hasSurface = false;

    inactivityTimer = new InactivityTimer(this);
    bircleBeepManager = new BircleBeepManager(this);
    ambientLightManager = new AmbientLightManager(this);

    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);

    toastText = "";
}

From source file:com.android.mms.ui.MessageUtils.java

public static int calculateWallpaperSize(Context context, int height, int width) {
    WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    int currentMaxHeight = windowManager.getDefaultDisplay().getHeight();
    int currentMaxWidth = windowManager.getDefaultDisplay().getWidth();
    MmsLog.d(TAG, "CurrentMaxHeight = " + currentMaxHeight + " CurrentMaxWidth = " + currentMaxWidth);
    int ratio = 1;
    while ((height / ratio) > currentMaxHeight || (width / ratio) > currentMaxWidth) {
        ratio *= 2;//from  w  w w. j a v  a2 s .  co m
    }
    return ratio;
}

From source file:com.ifoer.expeditionphone.MainActivity.java

private View downLoadAdobeReader() {
    WindowManager wm = (WindowManager) mContexts.getSystemService("window");
    this.width1 = wm.getDefaultDisplay().getWidth();
    this.height1 = wm.getDefaultDisplay().getHeight();
    this.tipsView = LayoutInflater.from(mContexts).inflate(C0136R.layout.download_adobe, null, false);
    this.version = (TextView) this.tipsView.findViewById(C0136R.id.about_text);
    this.version.setText(
            new StringBuilder(String.valueOf(mContexts.getResources().getString(C0136R.string.main_tools_pdf)))
                    .append(":").append(SpecilApiUtil.LINE_SEP)
                    .append("http://get.adobe.com/reader/otherversions/").toString());
    this.aboutKnowBtn = (Button) this.tipsView.findViewById(C0136R.id.ikonwBtn);
    this.aboutKnowBtn.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            MainActivity.this.aboutDialog.dismiss();
        }//from ww  w. j  av  a 2s .  c  o  m
    });
    return this.tipsView;
}

From source file:com.vonglasow.michael.satstat.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    defaultUEH = Thread.getDefaultUncaughtExceptionHandler();

    Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {
        public void uncaughtException(Thread t, Throwable e) {
            Context c = getApplicationContext();
            File dumpDir = c.getExternalFilesDir(null);
            File dumpFile = new File(dumpDir, "satstat-" + System.currentTimeMillis() + ".log");
            PrintStream s;// w w w. ja va2  s.  co m
            try {
                InputStream buildInStream = getResources().openRawResource(R.raw.build);
                s = new PrintStream(dumpFile);
                s.append("SatStat build: ");

                int i;
                try {
                    i = buildInStream.read();
                    while (i != -1) {
                        s.write(i);
                        i = buildInStream.read();
                    }
                    buildInStream.close();
                } catch (IOException e1) {
                    e1.printStackTrace();
                }

                s.append("\n\n");
                e.printStackTrace(s);
                s.flush();
                s.close();
            } catch (FileNotFoundException e2) {
                e2.printStackTrace();
            }
            defaultUEH.uncaughtException(t, e);
        }
    });

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

    final ActionBar actionBar = getActionBar();

    setContentView(R.layout.activity_main);

    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // Find out default screen orientation
    Configuration config = getResources().getConfiguration();
    WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
    int rot = wm.getDefaultDisplay().getRotation();
    isWideScreen = (config.orientation == Configuration.ORIENTATION_LANDSCAPE
            && (rot == Surface.ROTATION_0 || rot == Surface.ROTATION_180)
            || config.orientation == Configuration.ORIENTATION_PORTRAIT
                    && (rot == Surface.ROTATION_90 || rot == Surface.ROTATION_270));
    Log.d("MainActivity", "isWideScreen=" + Boolean.toString(isWideScreen));

    // compact action bar
    int dpX = (int) (this.getResources().getDisplayMetrics().widthPixels
            / this.getResources().getDisplayMetrics().density);
    /*
     * This is a crude way to ensure a one-line action bar with tabs
     * (not a drop-down list) and home (incon) and title only if there
     * is space, depending on screen width:
     * divide screen in units of 64 dp
     * each tab requires 1 unit, home and menu require slightly less,
     * title takes up approx. 2.5 units in portrait,
     * home and title are about 2 units wide in landscape
     */
    if (dpX < 192) {
        // just enough space for drop-down list and menu
        actionBar.setDisplayShowHomeEnabled(false);
        actionBar.setDisplayShowTitleEnabled(false);
    } else if (dpX < 320) {
        // not enough space for four tabs, but home will fit next to list
        actionBar.setDisplayShowHomeEnabled(true);
        actionBar.setDisplayShowTitleEnabled(false);
    } else if (dpX < 384) {
        // just enough space for four tabs
        actionBar.setDisplayShowHomeEnabled(false);
        actionBar.setDisplayShowTitleEnabled(false);
    } else if ((dpX < 448) || ((config.orientation == Configuration.ORIENTATION_PORTRAIT) && (dpX < 544))) {
        // space for four tabs and home, but not title
        actionBar.setDisplayShowHomeEnabled(true);
        actionBar.setDisplayShowTitleEnabled(false);
    } else {
        // ample space for home, title and all four tabs
        actionBar.setDisplayShowHomeEnabled(true);
        actionBar.setDisplayShowTitleEnabled(true);
    }
    setEmbeddedTabs(actionBar, true);

    providerLocations = new HashMap<String, Location>();

    mAvailableProviderStyles = new ArrayList<String>(Arrays.asList(LOCATION_PROVIDER_STYLES));

    providerStyles = new HashMap<String, String>();
    providerAppliedStyles = new HashMap<String, String>();

    providerInvalidationHandler = new Handler();
    providerInvalidators = new HashMap<String, Runnable>();

    // Create the adapter that will return a fragment for each of the three
    // primary sections of the app.
    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mSectionsPagerAdapter);
    mViewPager.setOnPageChangeListener(this);

    // Add tabs, specifying the tab's text and TabListener
    for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
        actionBar.addTab(actionBar.newTab()
                //.setText(mSectionsPagerAdapter.getPageTitle(i))
                .setIcon(mSectionsPagerAdapter.getPageIcon(i)).setTabListener(this));
    }

    // This is needed by the mapsforge library.
    AndroidGraphicFactory.createInstance(this.getApplication());

    // Get system services for event delivery
    mLocationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
    mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    mOrSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);
    mAccSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    mGyroSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
    mMagSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
    mLightSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);
    mProximitySensor = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);
    mPressureSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_PRESSURE);
    mHumiditySensor = mSensorManager.getDefaultSensor(Sensor.TYPE_RELATIVE_HUMIDITY);
    mTempSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_AMBIENT_TEMPERATURE);
    mTelephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    mConnectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);

    mAccSensorRes = getSensorDecimals(mAccSensor, mAccSensorRes);
    mGyroSensorRes = getSensorDecimals(mGyroSensor, mGyroSensorRes);
    mMagSensorRes = getSensorDecimals(mMagSensor, mMagSensorRes);
    mLightSensorRes = getSensorDecimals(mLightSensor, mLightSensorRes);
    mProximitySensorRes = getSensorDecimals(mProximitySensor, mProximitySensorRes);
    mPressureSensorRes = getSensorDecimals(mPressureSensor, mPressureSensorRes);
    mHumiditySensorRes = getSensorDecimals(mHumiditySensor, mHumiditySensorRes);
    mTempSensorRes = getSensorDecimals(mTempSensor, mTempSensorRes);

    networkTimehandler = new Handler();
    networkTimeRunnable = new Runnable() {
        @Override
        public void run() {
            int newNetworkType = mTelephonyManager.getNetworkType();
            if (getNetworkGeneration(newNetworkType) != mLastNetworkGen)
                onNetworkTypeChanged(newNetworkType);
            else
                networkTimehandler.postDelayed(this, NETWORK_REFRESH_DELAY);
        }
    };

    wifiTimehandler = new Handler();
    wifiTimeRunnable = new Runnable() {

        @Override
        public void run() {
            mWifiManager.startScan();
            wifiTimehandler.postDelayed(this, WIFI_REFRESH_DELAY);
        }
    };

    updateLocationProviderStyles();
}

From source file:org.chromium.android_webview.test.AwSettingsTest.java

@SmallTest
@Feature({ "AndroidWebView", "Preferences" })
public void testSetInitialScale() throws Throwable {
    final TestAwContentsClient contentClient = new TestAwContentsClient();
    final AwTestContainerView testContainerView = createAwTestContainerViewOnMainSync(contentClient);
    final AwContents awContents = testContainerView.getAwContents();
    final AwSettings awSettings = getAwSettingsOnUiThread(awContents);
    CallbackHelper onPageFinishedHelper = contentClient.getOnPageFinishedHelper();

    WindowManager wm = (WindowManager) getInstrumentation().getTargetContext()
            .getSystemService(Context.WINDOW_SERVICE);
    Point screenSize = new Point();
    wm.getDefaultDisplay().getSize(screenSize);
    // Make sure after 50% scale, page width still larger than screen.
    int height = screenSize.y * 2 + 1;
    int width = screenSize.x * 2 + 1;
    final String page = "<html><body>" + "<p style='height:" + height + "px;width:" + width + "px'>"
            + "testSetInitialScale</p></body></html>";
    final float defaultScale = getInstrumentation().getTargetContext().getResources()
            .getDisplayMetrics().density;

    assertEquals(defaultScale, getPixelScaleOnUiThread(awContents), .01f);
    loadDataSync(awContents, onPageFinishedHelper, page, "text/html", false);
    assertEquals(defaultScale, getPixelScaleOnUiThread(awContents), .01f);

    int onScaleChangedCallCount = contentClient.getOnScaleChangedHelper().getCallCount();
    awSettings.setInitialPageScale(50);//from  w w w  .  ja v a2s  .  c o  m
    loadDataSync(awContents, onPageFinishedHelper, page, "text/html", false);
    contentClient.getOnScaleChangedHelper().waitForCallback(onScaleChangedCallCount);
    assertEquals(0.5f, getPixelScaleOnUiThread(awContents), .01f);

    onScaleChangedCallCount = contentClient.getOnScaleChangedHelper().getCallCount();
    awSettings.setInitialPageScale(500);
    loadDataSync(awContents, onPageFinishedHelper, page, "text/html", false);
    contentClient.getOnScaleChangedHelper().waitForCallback(onScaleChangedCallCount);
    assertEquals(5.0f, getPixelScaleOnUiThread(awContents), .01f);

    onScaleChangedCallCount = contentClient.getOnScaleChangedHelper().getCallCount();
    awSettings.setInitialPageScale(0);
    loadDataSync(awContents, onPageFinishedHelper, page, "text/html", false);
    contentClient.getOnScaleChangedHelper().waitForCallback(onScaleChangedCallCount);
    assertEquals(defaultScale, getPixelScaleOnUiThread(awContents), .01f);
}