Android Open Source - android_device Screen Info Fragment






From Project

Back to project page android_device.

License

The source code is released under:

[Apache License](http://www.apache.org/licenses/): Version 2.0, January 2004 =============== ## TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION ## ### 1. Definitions. ### "License" sha...

If you think the Android project android_device listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * =================================================================================================
 *                Copyright (C) 2013 - 2014 Martin Albedinsky [Wolf-ITechnologies]
 * =================================================================================================
 *         Licensed under the Apache License, Version 2.0 or later (further "License" only).
 * -------------------------------------------------------------------------------------------------
 * You may use this file only in compliance with the License. More details and copy of this License
 * you may obtain at/*from  ww w . j ava  2s  .c o m*/
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * You can redistribute, modify or publish any part of the code written within this file but as it
 * is described in the License, the software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES or CONDITIONS OF ANY KIND.
 *
 * See the License for the specific language governing permissions and limitations under the License.
 * =================================================================================================
 */
package com.wit.android.device.examples.fragment;

import android.content.res.Resources;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;

import com.wit.android.device.examples.R;
import com.wit.android.device.examples.adapter.SimpleInfoAdapter;
import com.wit.android.device.examples.model.SimpleInfo;
import com.wit.android.device.Screen;
import com.wit.android.examples.libs.fragment.annotation.ExActionBarOptions;
import com.wit.android.examples.libs.fragment.annotation.ExContentView;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * Description.
 * </p>
 *
 * @author Martin Albedinsky
 */
@ExContentView(R.layout.fragment_listview)
@ExActionBarOptions(title = R.string.Navigation_Label_ScreenInfo)
public class ScreenInfoFragment extends BaseDeviceFragment {

  /**
   * Log TAG.
   */
  // private static final String TAG = ScreenInfoFragment.class.getSimpleName();

  /**
   */
  @Override
  public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    final Resources res = getResources();
    final Screen screen = getAndroidDevice().getScreen();

    // Obtain all information data about screen.
    final List<SimpleInfo> items = new ArrayList<>();
    /**
     * Screen width and height in the default orientation.
     */
    items.add(SimpleInfo.create(
        R.string.Screen_Info_Label_WidthAndHeight,
        res.getString(
            R.string.Screen_Info_Label_WidthAndHeight_format,
            screen.getWidth(),
            screen.getHeight()
        ),
        res
    ));
    /**
     * Screen current width and height.
     */
    items.add(SimpleInfo.create(
        R.string.Screen_Info_Label_CurrentWidthAndHeight,
        res.getString(
            R.string.Screen_Info_Label_WidthAndHeight_format,
            screen.getCurrentWidth(),
            screen.getCurrentHeight()
        ),
        res
    ));
    /**
     * Screen type (SMALL, NORMAL, ...) and density (MDPI, HDPI, ...).
     */
    items.add(SimpleInfo.create(
        R.string.Screen_Info_Label_TypeAndDensity,
        res.getString(
            R.string.Screen_Info_Label_TypeAndDensity_format,
            screen.getType().name(),
            screen.getDensity().name(),
            screen.getRawDensity()
        ),
        res
    ));
    /**
     * Screen diagonal distance.
     */
    items.add(SimpleInfo.create(
        R.string.Screen_Info_Label_DiagonalDistance,
        res.getString(
            R.string.Screen_Info_Label_DiagonalDistance_format,
            screen.getDiagonalDistance(false),
            screen.getDiagonalDistance(true)
        ),
        res
    ));
    /**
     * Screen density pixels vs. raw pixels calculations.
     */
    final int dpToPixel = 50;
    final int pixelToDp = 50;
    items.add(SimpleInfo.create(
        R.string.Screen_Info_Label_DensityPixelVsPixel,
        res.getString(
            R.string.Screen_Info_Label_DensityPixelVsPixel_format,
            screen.getScreenDP(),
            dpToPixel,
            screen.dpToPixel(dpToPixel),
            pixelToDp,
            screen.pixelToDP(pixelToDp)
        ),
        res
    ));
    /**
     * Screen default orientation.
     */
    items.add(SimpleInfo.create(
        R.string.Screen_Info_Label_DefaultOrientation,
        screen.getDefaultOrientation().name(),
        res
    ));
    /**
     * Screen current orientation.
     */
    items.add(SimpleInfo.create(
        R.string.Screen_Info_Label_CurrentOrientation,
        screen.getCurrentOrientation().name(),
        res
    ));
    /**
     * Screen current rotation.
     */
    items.add(SimpleInfo.create(
        R.string.Screen_Info_Label_CurrentRotation,
        screen.getCurrentRotation().name(),
        res
    ));
    /**
     * Screen refresh rate.
     */
    items.add(SimpleInfo.create(
        R.string.Screen_Info_Label_RefreshRate,
        res.getString(
            R.string.Screen_Info_Label_RefreshRate_format,
            screen.getRefreshRate()
        ),
        res
    ));
    /**
     * Screen system (user defined) brightness.
     */
    items.add(SimpleInfo.create(
        R.string.Screen_Info_Label_SystemBrightness,
        Float.toString(screen.getSystemBrightness()),
        res
    ));

    // Set up adapter.
    final SimpleInfoAdapter adapter = new SimpleInfoAdapter(getActivity());
    adapter.changeItems(items);

    // Set up list view.
    ((ListView) view.findViewById(android.R.id.list)).setAdapter(adapter);
  }
}




Java Source Code List

com.wit.android.device.AndroidDevice.java
com.wit.android.device.BatteryImpl.java
com.wit.android.device.Battery.java
com.wit.android.device.ConnectionImpl.java
com.wit.android.device.Connection.java
com.wit.android.device.DeviceConfig.java
com.wit.android.device.ScreenImpl.java
com.wit.android.device.Screen.java
com.wit.android.device.StorageAction.java
com.wit.android.device.StorageImpl.java
com.wit.android.device.Storage.java
com.wit.android.device.examples.HomeActivity.java
com.wit.android.device.examples.adapter.BatteryInfoAdapter.java
com.wit.android.device.examples.adapter.ConnectionInfoAdapter.java
com.wit.android.device.examples.adapter.FilesAdapter.java
com.wit.android.device.examples.adapter.OrientationsAdapter.java
com.wit.android.device.examples.adapter.SimpleInfoAdapter.java
com.wit.android.device.examples.adapter.StorageAdapter.java
com.wit.android.device.examples.dialog.NewFileDialog.java
com.wit.android.device.examples.fragment.BaseDeviceFragment.java
com.wit.android.device.examples.fragment.BatteryInfoFragment.java
com.wit.android.device.examples.fragment.ConnectionInfoFragment.java
com.wit.android.device.examples.fragment.DeviceInfoFragment.java
com.wit.android.device.examples.fragment.FragmentsFactory.java
com.wit.android.device.examples.fragment.ScreenInfoFragment.java
com.wit.android.device.examples.fragment.ScreenInterfaceFragment.java
com.wit.android.device.examples.fragment.StorageFilesFragment.java
com.wit.android.device.examples.fragment.StorageInfoFragment.java
com.wit.android.device.examples.fragment.StorageInterfaceFragment.java
com.wit.android.device.examples.model.BatteryInfo.java
com.wit.android.device.examples.model.ConnectionInfo.java
com.wit.android.device.examples.model.SimpleInfo.java
com.wit.android.device.examples.model.StorageItem.java
com.wit.android.device.examples.module.StorageAssistant.java
com.wit.android.device.receiver.BatteryHealthReceiver.java
com.wit.android.device.receiver.BatteryPluggedStateReceiver.java
com.wit.android.device.receiver.BatteryStatusReceiver.java
com.wit.android.device.receiver.BroadcastProcessor.java
com.wit.android.device.receiver.ConnectionStateReceiver.java
com.wit.android.device.util.ConnectionUtils.java
com.wit.android.device.util.ScreenUtils.java
com.wit.android.device.util.StorageEditor.java
com.wit.android.device.util.StorageUtils.java