Example usage for android.content.res Resources getBoolean

List of usage examples for android.content.res Resources getBoolean

Introduction

In this page you can find the example usage for android.content.res Resources getBoolean.

Prototype

public boolean getBoolean(@BoolRes int id) throws NotFoundException 

Source Link

Document

Return a boolean associated with a particular resource ID.

Usage

From source file:com.androzic.route.RouteDetails.java

@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
    Resources resources = getResources();
    if (getString(R.string.pref_wakelock).equals(key)) {
        getListView().setKeepScreenOn(/*w  ww  . j ava  2 s.  c  o m*/
                navigation && sharedPreferences.getBoolean(key, resources.getBoolean(R.bool.def_wakelock)));
    }
}

From source file:com.example.mapsample.view.ActionSheet.java

private boolean checkDeviceHasNavigationBar(Context context) {
    boolean hasNavigationBar = false;
    Resources rs = context.getResources();
    int id = rs.getIdentifier("config_showNavigationBar", "bool", "android");
    if (id > 0) {
        hasNavigationBar = rs.getBoolean(id);
    }/*from ww  w  .j  av a 2s. c  o m*/
    try {
        Class systemPropertiesClass = Class.forName("android.os.SystemProperties");
        Method m = systemPropertiesClass.getMethod("get", String.class);
        String navBarOverride = (String) m.invoke(systemPropertiesClass, "qemu.hw.mainkeys");
        if ("1".equals(navBarOverride)) {
            hasNavigationBar = false;
        } else if ("0".equals(navBarOverride)) {
            hasNavigationBar = true;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    return hasNavigationBar;

}

From source file:uc.ActionSheet.java

private boolean checkDeviceHasNavigationBar(Context context) {
    boolean hasNavigationBar = false;
    Resources rs = context.getResources();
    int id = rs.getIdentifier("config_showNavigationBar", "bool", "android");
    if (id > 0) {
        hasNavigationBar = rs.getBoolean(id);
    }/*from  www .j a  va 2s  .c  o  m*/
    try {
        @SuppressWarnings("rawtypes")
        Class systemPropertiesClass = Class.forName("android.os.SystemProperties");
        @SuppressWarnings("unchecked")
        Method m = systemPropertiesClass.getMethod("get", String.class);
        String navBarOverride = (String) m.invoke(systemPropertiesClass, "qemu.hw.mainkeys");
        if ("1".equals(navBarOverride)) {
            hasNavigationBar = false;
        } else if ("0".equals(navBarOverride)) {
            hasNavigationBar = true;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    return hasNavigationBar;

}

From source file:com.sourceallies.android.zonebeacon.activity.MainActivity.java

/**
 * Get the number of columns in the grid.
 *
 * @return integer for the number of columns used in the grid
 *//*from  w w w.ja  va  2 s.  c o m*/
@VisibleForTesting
protected int getColumnCount() {
    Resources res = getResources();

    if (res.getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)
        return 2;
    if (res.getBoolean(R.bool.tablet))
        return 2;

    return 1;
}

From source file:com.example.anumbrella.viewpager.UnderlinePagerIndicator.java

public UnderlinePagerIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    ////  w w w  .  ja  v a  2s  .c om
    if (isInEditMode()) {
        return;
    }

    //??
    final Resources res = getResources();

    //
    //?
    final boolean defaultFades = res.getBoolean(R.bool.default_underline_indicator_fades);
    //
    final int defaultFadeDelay = res.getInteger(R.integer.default_underline_indicator_fade_delay);
    //
    final int defaultFadeLength = res.getInteger(R.integer.default_underline_indicator_fade_length);
    //??
    final int defaultSelectedColor = res.getColor(R.color.default_underline_indicator_selected_color);

    //?xml
    TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.UnderlinePagerIndicator, defStyle, 0);

    setFades(array.getBoolean(R.styleable.UnderlinePagerIndicator_fades, defaultFades));
    setSelectedColor(array.getColor(R.styleable.UnderlinePagerIndicator_selectedColor, defaultSelectedColor));
    setFadeDelay(array.getInteger(R.styleable.UnderlinePagerIndicator_fadeDelay, defaultFadeDelay));
    setFadeLength(array.getInteger(R.styleable.UnderlinePagerIndicator_fadeLength, defaultFadeLength));

    Drawable background = array.getDrawable(R.styleable.UnderlinePagerIndicator_android_background);
    if (background != null) {
        setBackgroundDrawable(background);
    }
    array.recycle();

    final ViewConfiguration configuration = ViewConfiguration.get(context);
    //????(?????)
    mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
}

From source file:lewa.support.v7.internal.view.menu.ActionMenuItemView.java

public ActionMenuItemView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    // LEWA ADD BEGIN
    mContext = context;/*from  w ww.j  a v  a 2  s . c om*/
    // LEWA ADD END

    final Resources res = context.getResources();
    mAllowTextWithIcon = res.getBoolean(R.bool.abc_config_allowActionMenuItemTextWithIcon);
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ActionMenuItemView, defStyle, 0);
    mMinWidth = a.getDimensionPixelSize(R.styleable.ActionMenuItemView_android_minWidth, 0);
    a.recycle();

    final float density = res.getDisplayMetrics().density;
    // LEWA MODIFY BEGIN
    mMaxIconSize = Injector.getMaxIconSize(this);
    // LEWA MODIFY END

    // LEWA ADD BEGIN
    mMaxItemWidth = (int) (MAX_ITEM_WIDTH * density);
    // LEWA ADD END
    mMaxIconSize = (int) (MAX_ICON_SIZE * density + 0.5f);

    setOnClickListener(this);
    setOnLongClickListener(this);

    setTransformationMethod(new AllCapsTransformationMethod(context));

    mSavedPaddingLeft = -1;
    // LEWA ADD BEGIN
    Injector.initColorfulStyle(this);
    // LEWA ADD END
}

From source file:org.mariotaku.twidere.activity.HomeActivity.java

/** Called when the activity is first created. */
@Override//from  www . ja  v  a 2  s .com
public void onCreate(final Bundle savedInstanceState) {
    mApplication = getTwidereApplication();
    mTwitterWrapper = mApplication.getTwitterWrapper();
    mPreferences = getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
    mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    super.onCreate(savedInstanceState);
    sendBroadcast(new Intent(BROADCAST_HOME_ACTIVITY_ONCREATE));
    final Resources res = getResources();
    mDisplayAppIcon = res.getBoolean(R.bool.home_display_icon);
    final long[] account_ids = getAccountIds(this);
    if (account_ids.length <= 0) {
        final Intent intent = new Intent(INTENT_ACTION_TWITTER_LOGIN);
        intent.setClass(this, SignInActivity.class);
        startActivity(intent);
        finish();
        return;
    } else {
        setDefaultAccount();
    }
    final boolean refresh_on_start = mPreferences.getBoolean(PREFERENCE_KEY_REFRESH_ON_START, false);
    final Bundle bundle = getIntent().getExtras();
    int initial_tab = -1;
    if (bundle != null) {
        final long[] refreshed_ids = bundle.getLongArray(INTENT_KEY_IDS);
        if (refreshed_ids != null && !refresh_on_start && savedInstanceState == null) {
            mTwitterWrapper.refreshAll();
        }
        initial_tab = bundle.getInt(INTENT_KEY_INITIAL_TAB, -1);
        switch (initial_tab) {
        case TAB_POSITION_HOME: {
            mTwitterWrapper.clearNotification(NOTIFICATION_ID_HOME_TIMELINE);
            break;
        }
        case TAB_POSITION_MENTIONS: {
            mTwitterWrapper.clearNotification(NOTIFICATION_ID_MENTIONS);
            break;
        }
        case TAB_POSITION_MESSAGES: {
            mTwitterWrapper.clearNotification(NOTIFICATION_ID_DIRECT_MESSAGES);
            break;
        }
        }
    }
    mActionBar = getSupportActionBar();
    mActionBar.setCustomView(R.layout.base_tabs);
    mActionBar.setDisplayShowTitleEnabled(false);
    mActionBar.setDisplayShowCustomEnabled(true);
    mActionBar.setDisplayShowHomeEnabled(mDisplayAppIcon);
    if (mDisplayAppIcon) {
        ActivityAccessor.setHomeButtonEnabled(this, true);
    }
    final View view = mActionBar.getCustomView();

    mProgress = (ProgressBar) view.findViewById(android.R.id.progress);
    mIndicator = (TabPageIndicator) view.findViewById(android.R.id.tabs);
    final boolean tab_display_label = res.getBoolean(R.bool.tab_display_label);
    mAdapter = new TabsAdapter(this, getSupportFragmentManager(), mIndicator);
    mShowHomeTab = mPreferences.getBoolean(PREFERENCE_KEY_SHOW_HOME_TAB, true);
    mShowMentionsTab = mPreferences.getBoolean(PREFERENCE_KEY_SHOW_MENTIONS_TAB, true);
    mShowMessagesTab = mPreferences.getBoolean(PREFERENCE_KEY_SHOW_MESSAGES_TAB, true);
    mShowAccountsTab = mPreferences.getBoolean(PREFERENCE_KEY_SHOW_ACCOUNTS_TAB, true);
    initTabs(getTabs(this));
    mViewPager.setAdapter(mAdapter);
    mViewPager.setOffscreenPageLimit(3);
    mIndicator.setViewPager(mViewPager);
    mIndicator.setOnPageChangeListener(this);
    mIndicator.setDisplayLabel(tab_display_label);
    getSupportFragmentManager().addOnBackStackChangedListener(this);

    final boolean remember_position = mPreferences.getBoolean(PREFERENCE_KEY_REMEMBER_POSITION, true);
    final long[] activated_ids = getActivatedAccountIds(this);
    if (activated_ids.length <= 0) {
        startActivityForResult(new Intent(INTENT_ACTION_SELECT_ACCOUNT), REQUEST_SELECT_ACCOUNT);
    } else if (remember_position || initial_tab >= 0) {
        final int position = initial_tab >= 0 ? initial_tab
                : mPreferences.getInt(PREFERENCE_KEY_SAVED_TAB_POSITION, TAB_POSITION_HOME);
        if (position >= 0 || position < mViewPager.getChildCount()) {
            mViewPager.setCurrentItem(position);
        }
    }
    if (refresh_on_start && savedInstanceState == null) {
        mTwitterWrapper.refreshAll();
    }
    if (!mPreferences.getBoolean(PREFERENCE_KEY_API_UPGRADE_CONFIRMED, false)) {
        final FragmentManager fm = getSupportFragmentManager();
        if (fm.findFragmentByTag(FRAGMENT_TAG_API_UPGRADE_NOTICE) == null
                || !fm.findFragmentByTag(FRAGMENT_TAG_API_UPGRADE_NOTICE).isAdded()) {
            new APIUpgradeConfirmDialog().show(getSupportFragmentManager(), "api_upgrade_notice");
        }
    }

    if (mPreferences.getBoolean(PREFERENCE_KEY_SHOW_UCD_DATA_PROFILING_REQUEST, true)) {
        final Intent intent = new Intent(this, DataProfilingSettingsActivity.class);
        final PendingIntent content_intent = PendingIntent.getActivity(this, 0, intent, 0);
        final NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
        builder.setAutoCancel(true);
        builder.setSmallIcon(R.drawable.ic_stat_question_mark);
        builder.setTicker(getString(R.string.data_profiling_notification_ticker));
        builder.setContentTitle(getString(R.string.data_profiling_notification_title));
        builder.setContentText(getString(R.string.data_profiling_notification_desc));
        builder.setContentIntent(content_intent);
        mNotificationManager.notify(NOTIFICATION_ID_DATA_PROFILING, builder.build());
    }
}

From source file:com.duinopeak.balanbot.BalanbotActivity.java

@Override
public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
    if (D)//w ww  .  j  a v  a 2 s .  c o m
        Log.d(TAG, "onTabSelected: " + tab.getPosition());
    currentTabSelected = tab.getPosition();

    Resources mResources = getResources();
    if (mResources.getBoolean(R.bool.isTablet)
            && mResources.getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE
            && currentTabSelected == ViewPagerAdapter.INFO_FRAGMENT) { // Check if the last tab is selected in landscape mode
        currentTabSelected -= 1; // If so don't go any further
        ActionBar bar = getSupportActionBar();
        bar.selectTab(bar.getTabAt(currentTabSelected));
    }

    mUnderlinePageIndicator.setCurrentItem(currentTabSelected); // When the given tab is selected, switch to the corresponding page in the ViewPager
    CustomViewPager.setPagingEnabled(true);
    if (checkTab(ViewPagerAdapter.GRAPH_FRAGMENT) && mChatService != null) {
        if (mChatService.getState() == BluetoothChatService.STATE_CONNECTED) {
            mChatService.write(getKalman);
            if (GraphFragment.mToggleButton != null) {
                if (GraphFragment.mToggleButton.isChecked())
                    mChatService.write(imuBegin); // Request data
                else
                    mChatService.write(imuStop); // Stop sending data
            }
        }
    } else if (checkTab(ViewPagerAdapter.INFO_FRAGMENT) && mChatService != null) {
        if (mChatService.getState() == BluetoothChatService.STATE_CONNECTED) {
            mChatService.write(getInfo); // Update info
            if (InfoFragment.mToggleButton != null) {
                if (InfoFragment.mToggleButton.isChecked())
                    mChatService.write(statusBegin); // Request data
                else
                    mChatService.write(statusStop); // Stop sending data
            }
        }
    }
    if (!checkTab(ViewPagerAdapter.GRAPH_FRAGMENT)) { // Needed when the user rotates the screen
        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); // Hide the keyboard
        imm.hideSoftInputFromWindow(getWindow().getDecorView().getApplicationWindowToken(), 0);
    }
}

From source file:com.travel.ac.view.UnderlinePageIndicator.java

public UnderlinePageIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (isInEditMode())
        return;//from   w ww  .  java2  s .  c o m

    final Resources res = getResources();
    mTextPaint.setColor(Color.BLACK);
    mTextPaint.setStrokeWidth(5);
    mTextPaint.setTextSize(40);
    //Load defaults from resources
    final float defaultLineHeight = res.getInteger(R.integer.default_line_height);
    final boolean defaultFades = res.getBoolean(R.bool.default_underline_indicator_fades);
    final int defaultFadeDelay = res.getInteger(R.integer.default_underline_indicator_fade_delay);
    final int defaultFadeLength = res.getInteger(R.integer.default_underline_indicator_fade_length);
    final int defaultSelectedColor = res.getColor(R.color.default_underline_indicator_selected_color);

    //Retrieve styles attributes
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.UnderlinePageIndicator, defStyle, 0);

    mTabLineHeight = a.getFloat(R.styleable.UnderlinePageIndicator_tab_line_height, defaultLineHeight);
    setFades(a.getBoolean(R.styleable.UnderlinePageIndicator_fades, defaultFades));
    setSelectedColor(a.getColor(R.styleable.UnderlinePageIndicator_selectedColor, defaultSelectedColor));
    setFadeDelay(a.getInteger(R.styleable.UnderlinePageIndicator_fadeDelay, defaultFadeDelay));
    setFadeLength(a.getInteger(R.styleable.UnderlinePageIndicator_fadeLength, defaultFadeLength));

    Drawable background = a.getDrawable(R.styleable.UnderlinePageIndicator_android_background);
    if (background != null) {
        setBackgroundDrawable(background);
    }
    a.recycle();

    final ViewConfiguration configuration = ViewConfiguration.get(context);
    mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
}

From source file:com.edutech.eBalanbot.eBalanbotActivity.java

@Override
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    activity = this;
    context = getApplicationContext();/*from   w  w w.  j a v a2s.  c  om*/

    if (!getResources().getBoolean(R.bool.isTablet))
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); // Set portrait mode only - for small screens like phones
    else {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2)
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_USER); // Full screen rotation
        else
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR); // Full screen rotation
        new Handler().postDelayed(new Runnable() { // Hack to hide keyboard when the layout it rotated
            @Override
            public void run() {
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); // Hide the keyboard - this is needed when the device is rotated
                imm.hideSoftInputFromWindow(getWindow().getDecorView().getApplicationWindowToken(), 0);
            }
        }, 1000);
    }

    setContentView(R.layout.activity_main);

    // Get local Bluetooth adapter
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2)
        mBluetoothAdapter = ((BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE)).getAdapter();
    else
        mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

    // If the adapter is null, then Bluetooth is not supported
    if (mBluetoothAdapter == null) {
        showToast("Bluetooth is not available", Toast.LENGTH_LONG);
        finish();
        return;
    }

    // get sensorManager and initialize sensor listeners
    SensorManager mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
    mSensorFusion = new SensorFusion(getApplicationContext(), mSensorManager);

    // Set up the action bar.
    final ActionBar actionBar = getSupportActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    actionBar.setDisplayHomeAsUpEnabled(true);
    // Create the adapter that will return a fragment for each of the primary sections of the app.
    ViewPagerAdapter mViewPagerAdapter = new ViewPagerAdapter(getApplicationContext(),
            getSupportFragmentManager());

    // Set up the ViewPager with the adapter.
    CustomViewPager mViewPager = (CustomViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mViewPagerAdapter);

    if (getResources().getBoolean(R.bool.isTablet))
        mViewPager.setOffscreenPageLimit(2); // Since two fragments is selected in landscape mode, this is used to smooth things out

    // Bind the underline indicator to the adapter
    mUnderlinePageIndicator = (UnderlinePageIndicator) findViewById(R.id.indicator);
    mUnderlinePageIndicator.setViewPager(mViewPager);
    mUnderlinePageIndicator.setFades(false);

    // When swiping between different sections, select the corresponding
    // tab. We can also use ActionBar.Tab#select() to do this if we have
    // a reference to the Tab.
    mUnderlinePageIndicator.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            if (D)
                Log.d(TAG, "ViewPager position: " + position);
            if (position < actionBar.getTabCount()) // Needed for when in landscape mode
                actionBar.setSelectedNavigationItem(position);
            else
                mUnderlinePageIndicator.setCurrentItem(position - 1);
        }
    });

    int count = mViewPagerAdapter.getCount();
    Resources mResources = getResources();
    boolean landscape = false;
    if (mResources.getBoolean(R.bool.isTablet)
            && mResources.getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
        landscape = true;
        count -= 1; // There is one less tab when in landscape mode
    }

    for (int i = 0; i < count; i++) { // For each of the sections in the app, add a tab to the action bar
        String text;
        if (landscape && i == count - 1)
            text = mViewPagerAdapter.getPageTitle(i) + " & " + mViewPagerAdapter.getPageTitle(i + 1); // Last tab in landscape mode have two titles in one tab
        else
            text = mViewPagerAdapter.getPageTitle(i).toString();

        // Create a tab with text corresponding to the page title defined by
        // the adapter. Also specify this Activity object, which implements
        // the TabListener interface, as the callback (listener) for when
        // this tab is selected.
        actionBar.addTab(actionBar.newTab().setText(text).setTabListener(this));
    }
    try {
        PackageManager mPackageManager = getPackageManager();
        if (mPackageManager != null)
            eBalanbotActivity.appVersion = mPackageManager.getPackageInfo(getPackageName(), 0).versionName; // Read the app version name
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }
}