Example usage for android.content.res TypedArray length

List of usage examples for android.content.res TypedArray length

Introduction

In this page you can find the example usage for android.content.res TypedArray length.

Prototype

public int length() 

Source Link

Document

Returns the number of values in this array.

Usage

From source file:com.cc.signalinfo.fragments.SignalFragment.java

/**
 * Gets the TextViews that map to the signal info data in the code for binding.
 *
 * @param sigInfoIds - the array containing the IDs to the TextView resources
 * @param refreshMap - should we recreate the map or reuse it? (in case we some reason added some, somehow)
 * @return map of the Signal data enumeration types (keys) and corresponding TextViews (values)
 *///from www.  j av a2s.c om
public Map<Signal, TextView> getSignalTextViewMap(TypedArray sigInfoIds, boolean refreshMap) {
    // no reason to do this over and over if it's already filled (we keep the same text stuff
    if (signalTextViewMap.isEmpty() || refreshMap) {
        Signal[] values = Signal.values();

        for (int i = 0; i <= sigInfoIds.length(); ++i) {
            int id = sigInfoIds.getResourceId(i, -1);

            if (id != -1) {
                TextView currentView = (TextView) rootView.findViewById(id);
                signalTextViewMap.put(values[i], currentView);
            }
        }
    }
    return Collections.unmodifiableMap(signalTextViewMap);
}

From source file:de.baumann.hhsmoodle.HHS_MainScreen.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_screen_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);/*  w ww.  j  av a  2s. c om*/
    helper_security.checkPin(HHS_MainScreen.this);
    helper_security.grantPermissions(HHS_MainScreen.this);
    helper_main.onStart(HHS_MainScreen.this);

    PreferenceManager.setDefaultValues(this, R.xml.user_settings, false);
    sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
    sharedPref.edit().putString("browserLoad", "").apply();
    class_SecurePreferences sharedPrefSec = new class_SecurePreferences(HHS_MainScreen.this, "sharedPrefSec",
            "Ywn-YM.XK$b:/:&CsL8;=L,y4", true);

    viewPager = (ViewPager) findViewById(R.id.viewpager);
    setupViewPager(viewPager);

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar,
            R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.addDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    View headerView = navigationView.getHeaderView(0);
    TextView nav_user = (TextView) headerView.findViewById(R.id.usernameNav);
    nav_user.setText(sharedPrefSec.getString("username"));

    TypedArray images = getResources().obtainTypedArray(R.array.splash_images);
    int choice = (int) (Math.random() * images.length());
    headerView.setBackgroundResource(images.getResourceId(choice, R.drawable.splash1));
    images.recycle();

    if (!appDir().exists()) {
        if (android.os.Build.VERSION.SDK_INT >= 23) {
            int hasWRITE_EXTERNAL_STORAGE = checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE);
            if (hasWRITE_EXTERNAL_STORAGE == PackageManager.PERMISSION_GRANTED) {
                if (!appDir().exists()) {
                    appDir().mkdirs();
                } else {
                    helper_security.grantPermissions(HHS_MainScreen.this);
                }
            }
        } else {
            appDir().mkdirs();
        }
    }

    onNewIntent(getIntent());

    if (sharedPref.getBoolean("silent_mode", true)) {
        final NotificationManager notificationManager = (NotificationManager) HHS_MainScreen.this
                .getSystemService(Context.NOTIFICATION_SERVICE);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N
                && !notificationManager.isNotificationPolicyAccessGranted()) {
            if (sharedPref.getString("show_permission_disturb", "true").equals("true")) {
                new android.app.AlertDialog.Builder(this).setTitle(R.string.app_permissions_title_dist)
                        .setMessage(helper_main.textSpannable(getString(R.string.app_permissions_dist)))
                        .setNeutralButton(R.string.toast_notAgain, new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.cancel();
                                sharedPref.edit().putString("show_permission_disturb", "false").apply();
                            }
                        }).setPositiveButton(getString(R.string.toast_yes),
                                new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N
                                                && !notificationManager.isNotificationPolicyAccessGranted()) {
                                            Intent intent = new Intent(
                                                    android.provider.Settings.ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS);
                                            startActivity(intent);
                                        }
                                    }
                                })
                        .setNegativeButton(getString(R.string.toast_cancel), null).show();
            }
        }
    }
}

From source file:com.nikola.despotoski.drawerlayoutedgetoggle.DrawerLayoutEdgeToggle.java

private int iterateAttributesForActionBarSherlock() {
    PackageInfo packageInfo;//w  ww.ja va2  s. co  m
    try {
        packageInfo = mActivity.getPackageManager().getPackageInfo(mActivity.getPackageName(),
                PackageManager.GET_META_DATA);
        int themeId = packageInfo.applicationInfo.theme;
        TypedArray themeAttributes = mActivity.getResources().obtainTypedArray(themeId);
        for (int i = 0; i < themeAttributes.length(); i++) {
            try {
                TypedValue v = new TypedValue();
                themeAttributes.getValue(i, v);
                String attName = mActivity.getResources().getResourceEntryName(v.resourceId);
                if (attName != null && attName.contains("actionbarsherlock")
                        && attName.contains("actionBarSize")) {
                    return v.data;
                }
            } catch (Exception e) {
                Log.e("ResourceNotFound", "" + e.getMessage());
            }
        }
        themeAttributes.recycle();
    } catch (NameNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return 0;

}

From source file:tinkercoder.stockcalculator.calculator.Calculator.java

@Override
public void onCreate(Bundle state) {
    super.onCreate(state);
    super.setInflaterOnView("calculator");
    super.getDrawerList().setItemChecked(0, true);

    // find and load ads
    AdView adView = (AdView) findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
            .addTestDevice("98C719A04DF7111D2DDD25D764C88F8E").build();
    if (adView != null) {
        adView.loadAd(adRequest);/*w w  w  .  j  a  v  a2s.  c o  m*/
    }

    // Disable IME for this application
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
            WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);

    mPager = (ViewPager) findViewById(R.id.panelswitch);
    if (mPager != null) {
        isSingleUI = false;
        mPager.setAdapter(new PageAdapter(mPager));
    } else {
        // Single page UI
        isSingleUI = true;
        final TypedArray buttons = getResources().obtainTypedArray(R.array.buttons);
        for (int i = 0; i < buttons.length(); i++) {
            setOnClickListener(null, buttons.getResourceId(i, 0));
        }
        buttons.recycle();
    }

    if (mClearButton == null) {
        mClearButton = findViewById(R.id.clear);
        mClearButton.setOnClickListener(mListener);
        mClearButton.setOnLongClickListener(mListener);
    }
    if (mBackspaceButton == null) {
        mBackspaceButton = findViewById(R.id.del);
        mBackspaceButton.setOnClickListener(mListener);
        mBackspaceButton.setOnLongClickListener(mListener);
    }

    mPersist = new Persist(this);
    mPersist.load();

    mHistory = mPersist.history;

    mDisplay = (CalculatorDisplay) findViewById(R.id.display);

    mLogic = new Logic(this, mHistory, mDisplay);
    mLogic.setListener(this);

    mLogic.setDeleteMode(mPersist.getDeleteMode());
    mLogic.setLineLength(mDisplay.getMaxDigits());

    HistoryAdapter historyAdapter = new HistoryAdapter(this, mHistory, mLogic);
    mHistory.setObserver(historyAdapter);

    if (mPager != null) {
        mPager.setCurrentItem(state == null ? 0 : state.getInt(STATE_CURRENT_VIEW, 0));
    }

    mListener.setHandler(mLogic, mPager);
    mDisplay.setOnKeyListener(mListener);

    if (!hasPermanentMenuKey(ViewConfiguration.get(this))) {
        createFakeMenu();
    }

    mLogic.resumeWithHistory();
    updateDeleteMode();

    // launcher notification
    sharedPref = prefSetting.getSharedPreferences(this);

    if (sharedPref.getBoolean("disableNotification_calculator", false)) {
        // dont send notification
    } else {
        notificationLauncher();
    }
}

From source file:com.kevinsoft.calculator.Calculator.java

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

    // Disable IME for this application
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
            WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);

    setContentView(R.layout.main);/*w w w  .  j a v a2s  . c  o m*/
    mPager = (ViewPager) findViewById(R.id.panelswitch);
    if (mPager != null) {
        mPager.setAdapter(new PageAdapter(mPager));
    } else {
        // Single page UI
        final TypedArray buttons = getResources().obtainTypedArray(R.array.buttons);
        for (int i = 0; i < buttons.length(); i++) {
            setOnClickListener(null, buttons.getResourceId(i, 0));
        }
        buttons.recycle();
    }

    if (mClearButton == null) {
        mClearButton = findViewById(R.id.clear);
        mClearButton.setOnClickListener(mListener);
        mClearButton.setOnLongClickListener(mListener);
    }
    if (mBackspaceButton == null) {
        mBackspaceButton = findViewById(R.id.del);
        mBackspaceButton.setOnClickListener(mListener);
        mBackspaceButton.setOnLongClickListener(mListener);
    }

    mPersist = new Persist(this);
    mPersist.load();

    mHistory = mPersist.history;

    mDisplay = (CalculatorDisplay) findViewById(R.id.display);

    mLogic = new Logic(this, mHistory, mDisplay);
    mLogic.setListener(this);

    mLogic.setDeleteMode(mPersist.getDeleteMode());
    mLogic.setLineLength(mDisplay.getMaxDigits());

    mHistoryAdapter = new HistoryAdapter(this, mHistory, mLogic);
    mHistory.setObserver(mHistoryAdapter);

    if (mPager != null) {
        mPager.setCurrentItem(state == null ? 0 : state.getInt(STATE_CURRENT_VIEW, 0));
    }

    mListener.setHandler(mLogic, mPager);
    mDisplay.setOnKeyListener(mListener);

    if (!ViewConfiguration.get(this).hasPermanentMenuKey()) {
        createFakeMenu();
    }

    mLogic.resumeWithHistory();
    updateDeleteMode();
    KevinSoundManager.getInstance().initSounds(this);

    SlidingUpPanelLayout layout = (SlidingUpPanelLayout) findViewById(R.id.sliding_layout);
    layout.setShadowDrawable(getResources().getDrawable(R.drawable.above_shadow));

    layout.setPanelSlideListener(new PanelSlideListener() {
        @Override
        public void onPanelSlide(View panel, float slideOffset) {
            Log.i(LOG_TAG, "onPanelSlide, offset " + slideOffset);
        }

        @Override
        public void onPanelExpanded(View panel) {
            Log.i(LOG_TAG, "onPanelExpanded");

        }

        @Override
        public void onPanelCollapsed(View panel) {
            Log.i(LOG_TAG, "onPanelCollapsed");

        }

        @Override
        public void onPanelAnchored(View panel) {
            Log.i(LOG_TAG, "onPanelAnchored");

        }
    });

    mHistoryView = (EnhancedListView) findViewById(R.id.historyList);

    setUpHistory();

    ImageButton ib = (ImageButton) findViewById(R.id.clear_all_history);
    ib.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            mHistoryAdapter.removeAll();
            mDisplay.setText("0", CalculatorDisplay.Scroll.RIGHT);

        }
    });

    ImageButton addAllb = (ImageButton) findViewById(R.id.add_all_history);
    addAllb.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            mHistoryAdapter.addAll();
        }
    });

}

From source file:com.google.android.apps.santatracker.village.Village.java

public int[] getIntArray(Resources resources, int resId) {
    TypedArray array = resources.obtainTypedArray(resId);
    int[] rc = new int[array.length()];
    TypedValue value = new TypedValue();
    for (int i = 0; i < array.length(); i++) {
        array.getValue(i, value);/*from  w w w.  j a v  a2  s .  c  o m*/
        rc[i] = value.resourceId;
    }
    array.recycle();
    return rc;
}

From source file:us.phyxsi.gameshelf.ui.FeedAdapter.java

public FeedAdapter(Activity hostActivity, Context context, DataLoadingSubject dataLoading, int columns) {
    this.host = hostActivity;
    this.context = context;
    this.dataLoading = dataLoading;
    dataLoading.addCallbacks(this);
    this.columns = columns;
    layoutInflater = LayoutInflater.from(host);
    comparator = new BoardgameComparator();
    items = new ArrayList<>();
    setHasStableIds(true);/*  www .  j  av  a  2s  . com*/
    TypedArray placeholderColors = hostActivity.getResources().obtainTypedArray(R.array.loading_placeholders);
    shotLoadingPlaceholders = new ColorDrawable[placeholderColors.length()];
    for (int i = 0; i < placeholderColors.length(); i++) {
        shotLoadingPlaceholders[i] = new ColorDrawable(placeholderColors.getColor(i, Color.DKGRAY));
    }
}

From source file:com.cc.signalinfo.activities.MainActivity.java

/**
 * Gets the TextViews that map to the signal info data in the code for binding.
 *
 * @param sigInfoIds - the array containing the IDs to the TextView resources
 * @param refreshMap - should we recreate the map or reuse it? (in case we some reason added some, somehow)
 * @return map of the Signal data enumeration types (keys) and corresponding TextViews (values)
 *///www.ja va  2  s  .  c om
public Map<Signal, TextView> getSignalTextViewMap(TypedArray sigInfoIds, boolean refreshMap) {
    // no reason to do this over and over if it's already filled (we keep the same text stuff)
    if (signalTextViewMap.isEmpty() || refreshMap) {
        Signal[] values = Signal.values();

        for (int i = 0; i < sigInfoIds.length(); ++i) {
            int id = sigInfoIds.getResourceId(i, -1);

            if (id != -1) {
                TextView currentView = (TextView) findViewById(id);
                signalTextViewMap.put(values[i], currentView);
            }
        }
    }
    return Collections.unmodifiableMap(signalTextViewMap);
}

From source file:com.hannesdorfmann.FeedAdapter.java

public FeedAdapter(Activity hostActivity, int columns, boolean pocketInstalled) {
    this.host = hostActivity;
    this.columns = columns;
    this.pocketIsInstalled = pocketInstalled;
    layoutInflater = LayoutInflater.from(host);
    comparator = new PlaidItemComparator();
    items = new ArrayList<>();
    setHasStableIds(true);//from w  w  w.  j a v  a2 s. c  o  m
    TypedArray placeholderColors = hostActivity.getResources().obtainTypedArray(R.array.loading_placeholders);
    shotLoadingPlaceholders = new ColorDrawable[placeholderColors.length()];
    for (int i = 0; i < placeholderColors.length(); i++) {
        shotLoadingPlaceholders[i] = new ColorDrawable(placeholderColors.getColor(i, Color.DKGRAY));
    }
}

From source file:io.plaidapp.ui.FeedAdapter.java

public FeedAdapter(Activity hostActivity, DataLoadingSubject dataLoading, int columns,
        boolean pocketInstalled) {
    this.host = hostActivity;
    this.dataLoading = dataLoading;
    this.columns = columns;
    this.pocketIsInstalled = pocketInstalled;
    layoutInflater = LayoutInflater.from(host);
    comparator = new PlaidItemComparator();
    items = new ArrayList<>();
    setHasStableIds(true);//from  w  w  w .  java 2s. com
    TypedArray placeholderColors = hostActivity.getResources().obtainTypedArray(R.array.loading_placeholders);
    shotLoadingPlaceholders = new ColorDrawable[placeholderColors.length()];
    for (int i = 0; i < placeholderColors.length(); i++) {
        shotLoadingPlaceholders[i] = new ColorDrawable(placeholderColors.getColor(i, Color.DKGRAY));
    }
}