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:de.baumann.thema.FragmentWallpaper.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.wallpaper, container, false);

    setHasOptionsMenu(true);// w  ww .j  a  v  a 2 s  .co  m

    final String[] itemTITLE = { getString(R.string.amber) + " - Lollipop",
            getString(R.string.blue) + " - Lollipop", getString(R.string.green) + " - Lollipop",
            getString(R.string.grey) + " - Lollipop", getString(R.string.red) + " - Lollipop",
            getString(R.string.teal) + " - Lollipop",

            getString(R.string.amber) + " - Marshmallow", getString(R.string.blue) + " - Marshmallow",
            getString(R.string.green) + " - Marshmallow", getString(R.string.grey) + " - Marshmallow",
            getString(R.string.red) + " - Marshmallow", getString(R.string.teal) + " - Marshmallow",

            getString(R.string.amber) + " - Nougat", getString(R.string.blue) + " - Nougat",
            getString(R.string.green) + " - Nougat", getString(R.string.grey) + " - Nougat",
            getString(R.string.red) + " - Nougat", getString(R.string.teal) + " - Nougat", };

    final String[] itemDES = {
            "CC license: https://github.com/scoute-dich/Blue-Minimal/blob/master/theme/src/main/res/drawable-nodpi/wp_lp_amber.png",
            "CC license: https://github.com/scoute-dich/Blue-Minimal/blob/master/theme/src/main/res/drawable-nodpi/wp_lp_blue.png",
            "CC license: https://github.com/scoute-dich/Blue-Minimal/blob/master/theme/src/main/res/drawable-nodpi/wp_lp_green.png",
            "CC license: https://github.com/scoute-dich/Blue-Minimal/blob/master/theme/src/main/res/drawable-nodpi/wp_lp_grey.png",
            "CC license: https://github.com/scoute-dich/Blue-Minimal/blob/master/theme/src/main/res/drawable-nodpi/wp_lp_red.png",
            "CC license: https://github.com/scoute-dich/Blue-Minimal/blob/master/theme/src/main/res/drawable-nodpi/wp_lp_teal.png",

            "CC license: https://github.com/scoute-dich/Blue-Minimal/blob/master/theme/src/main/res/drawable-nodpi/wp_mm_amber.png",
            "CC license: https://github.com/scoute-dich/Blue-Minimal/blob/master/theme/src/main/res/drawable-nodpi/wp_mm_blue.png",
            "CC license: https://github.com/scoute-dich/Blue-Minimal/blob/master/theme/src/main/res/drawable-nodpi/wp_mm_green.png",
            "CC license: https://github.com/scoute-dich/Blue-Minimal/blob/master/theme/src/main/res/drawable-nodpi/wp_mm_grey.png",
            "CC license: https://github.com/scoute-dich/Blue-Minimal/blob/master/theme/src/main/res/drawable-nodpi/wp_mm_red.png",
            "CC license: https://github.com/scoute-dich/Blue-Minimal/blob/master/theme/src/main/res/drawable-nodpi/wp_mm_teal.png",

            "CC license: https://github.com/scoute-dich/Blue-Minimal/blob/master/theme/src/main/res/drawable-nodpi/wp_n_amber.png",
            "CC license: https://github.com/scoute-dich/Blue-Minimal/blob/master/theme/src/main/res/drawable-nodpi/wp_n_blue.png",
            "CC license: https://github.com/scoute-dich/Blue-Minimal/blob/master/theme/src/main/res/drawable-nodpi/wp_n_green.png",
            "CC license: https://github.com/scoute-dich/Blue-Minimal/blob/master/theme/src/main/res/drawable-nodpi/wp_n_grey.png",
            "CC license: https://github.com/scoute-dich/Blue-Minimal/blob/master/theme/src/main/res/drawable-nodpi/wp_mm_red.png",
            "CC license: https://github.com/scoute-dich/Blue-Minimal/blob/master/theme/src/main/res/drawable-nodpi/wp_mm_teal.png", };

    final int[] itemPATH = { R.drawable.wp_lp_amber, R.drawable.wp_lp_blue, R.drawable.wp_lp_green,
            R.drawable.wp_lp_grey, R.drawable.wp_lp_red, R.drawable.wp_lp_teal,

            R.drawable.wp_mm_amber, R.drawable.wp_mm_blue, R.drawable.wp_mm_green, R.drawable.wp_mm_grey,
            R.drawable.wp_mm_red, R.drawable.wp_mm_teal,

            R.drawable.wp_n_amber, R.drawable.wp_n_blue, R.drawable.wp_n_green, R.drawable.wp_n_grey,
            R.drawable.wp_n_red, R.drawable.wp_n_teal, };

    final int[] itemPATHPREV = { R.drawable.wp_lp_amber_preview, R.drawable.wp_lp_blue_preview,
            R.drawable.wp_lp_green_preview, R.drawable.wp_lp_grey_preview, R.drawable.wp_lp_red_preview,
            R.drawable.wp_lp_teal_preview,

            R.drawable.wp_mm_amber_preview, R.drawable.wp_mm_blue_preview, R.drawable.wp_mm_green_preview,
            R.drawable.wp_mm_grey_preview, R.drawable.wp_mm_red_preview, R.drawable.wp_mm_teal_preview,

            R.drawable.wp_n_amber_preview, R.drawable.wp_n_blue_preview, R.drawable.wp_n_green_preview,
            R.drawable.wp_n_grey_preview, R.drawable.wp_n_red_preview, R.drawable.wp_n_teal_preview, };

    imgHeader = (ImageView) rootView.findViewById(R.id.imageView_header);

    if (imgHeader != null) {
        TypedArray images = getResources().obtainTypedArray(R.array.splash_images);
        int choice = (int) (Math.random() * images.length());
        imgHeader.setImageResource(images.getResourceId(choice, R.drawable.wp_lp_amber));
        images.recycle();
    }

    CustomListAdapter_Wallpaper adapter = new CustomListAdapter_Wallpaper(getActivity(), itemTITLE, itemDES,
            itemPATH, itemPATHPREV);
    ListView listView = (ListView) rootView.findViewById(R.id.bookmarks);
    listView.setAdapter(adapter);

    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // TODO Auto-generated method stub
            int Selecteditem = itemPATH[+position];
            assert imgHeader != null;
            imgHeader.setImageResource(Selecteditem);
        }
    });

    listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {

            final String SelecteditemUrl = itemDES[+position].substring(12);

            Uri uri = Uri.parse(SelecteditemUrl); // missing 'http://' will cause crashed
            Intent intent = new Intent(Intent.ACTION_VIEW, uri);
            startActivity(intent);

            return true;
        }
    });

    FloatingActionButton fab = (FloatingActionButton) rootView.findViewById(R.id.fab_wp);
    fab.setImageResource(R.drawable.check);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            if ((imgHeader != null ? imgHeader.getDrawable() : null) == null) {
                Snackbar.make(imgHeader, R.string.check_wallpaper, Snackbar.LENGTH_LONG).show();
            } else {
                Snackbar.make(imgHeader, R.string.applying, Snackbar.LENGTH_LONG).show();

                WallpaperManager myWallpaperManager = WallpaperManager.getInstance(getActivity());
                try {
                    Bitmap bitmap = ((BitmapDrawable) imgHeader.getDrawable()).getBitmap();
                    if (bitmap != null)
                        myWallpaperManager.setBitmap(bitmap);
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
    });

    return rootView;
}

From source file:org.onebusaway.android.ui.TutorialFragment.java

private void setupViews() {
    TypedArray typedArray = getResources().obtainTypedArray(imageArrayResourceId);
    String[] texts = getResources().getStringArray(stringArrayResourceId);
    images = new int[typedArray.length()];
    for (int i = 0; i < typedArray.length(); i++) {
        images[i] = typedArray.getResourceId(i, -1);
    }//from   w  ww  . ja  va 2 s .c  om
    typedArray.recycle();

    updatePagerIndicator(0, images.length);

    viewPager = (ViewPager) getActivity().findViewById(R.id.pager);
    PagerAdapter adapter = new ImageAdapter(getActivity(), images, texts);
    viewPager.setOffscreenPageLimit(3);
    viewPager.setAdapter(adapter);
    viewPager.addOnPageChangeListener(this);
    pagerDone = ((Button) getActivity().findViewById(R.id.pager_button_done));
    pagerNext = ((Button) getActivity().findViewById(R.id.pager_button_next));
    pagerPrev = ((Button) getActivity().findViewById(R.id.pager_button_prev));
    pagerDone.setOnClickListener(this);
    pagerPrev.setOnClickListener(this);
    pagerNext.setOnClickListener(this);
}

From source file:com.jikexueyuan.jikecalculator.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);//from   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());

    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);

    mLogic.resumeWithHistory();
    updateDeleteMode();
    SoundManager.getInstance().initSounds(this);
}

From source file:com.onyx.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);//from   ww w. j av a2  s  .co  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());

    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 (!ViewConfiguration.get(this).hasPermanentMenuKey()) {
        createFakeMenu();
    }

    mLogic.resumeWithHistory();
    updateDeleteMode();
}

From source file:io.vit.vitio.Navigation.NavigationDrawerFragment.java

public List<NavigationDrawerInfo> getData() {
    List<NavigationDrawerInfo> list = new ArrayList<>();
    String[] titles = getActivity().getResources().getStringArray(R.array.drawer_list_titles);
    TypedArray icon = getActivity().getResources().obtainTypedArray(R.array.drawer_icons);
    int[] ico = new int[icon.length()];
    for (int j = 0; j < ico.length; j++) {
        ico[j] = icon.getResourceId(j, -1);
    }//from   w ww . ja  v  a 2 s .  co m
    for (int i = 0; i < titles.length && i < ico.length; i++) {
        NavigationDrawerInfo info = new NavigationDrawerInfo();
        info.name = titles[i];
        info.iconId = ico[i];
        list.add(info);
    }
    return list;

}

From source file:com.aman.stockcalculator.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);//from ww  w  .  ja v  a  2 s.  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());

    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 (!ViewConfiguration.get(this).hasPermanentMenuKey()) {
        createFakeMenu();
    }

    mLogic.resumeWithHistory();
    updateDeleteMode();
}

From source file:com.hongfeiyu.hfykitkat.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);/*from   w w w.jav  a 2  s  .c  om*/
    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());

    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);

    mLogic.resumeWithHistory();
    updateDeleteMode();

    //?SoundManager
    SoundManager.getInstance().initSounds(this);

}

From source file:com.z.blast.workbox.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.calculator_main);
    mPager = (ViewPager) findViewById(R.id.panelswitch);
    if (mPager != null) {
        mPager.setAdapter(new PageAdapter(mPager));
    } else {/*from   ww w .j  a  v  a2s .  c  om*/
        // 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());

    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 (!ViewConfiguration.get(this).hasPermanentMenuKey()) {
        createFakeMenu();
    }

    mLogic.resumeWithHistory();
    updateDeleteMode();
}

From source file:com.mikecorrigan.trainscorekeeper.FragmentSummary.java

@SuppressLint("NewApi")
@Override//  w  w w.j  ava 2s .  c  om
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Log.vc(VERBOSE, TAG, "onCreateView: inflater=" + inflater + ", container=" + container
            + ", savedInstanceState=" + Utils.bundleToString(savedInstanceState));

    View rootView = inflater.inflate(R.layout.fragment_summary, container, false);

    final MainActivity activity = (MainActivity) getActivity();
    final Context context = activity;
    final Resources resources = context.getResources();

    // Get the model and attach a listener.
    game = activity.getGame();
    if (game != null) {
        game.addListener(mGameListener);
    }

    players = activity.getPlayers();

    // Get resources.
    String[] playerNames = resources.getStringArray(R.array.playerNames);

    TypedArray drawablesArray = resources.obtainTypedArray(R.array.playerDrawables);

    TypedArray playerTextColorsArray = resources.obtainTypedArray(R.array.playerTextColors);
    int[] playerTextColorsIds = new int[playerTextColorsArray.length()];
    for (int i = 0; i < playerTextColorsArray.length(); i++) {
        playerTextColorsIds[i] = playerTextColorsArray.getResourceId(i, -1);
    }

    // Get root view.
    ScrollView scrollView = (ScrollView) rootView.findViewById(R.id.scroll_view);

    // Create table.
    tableLayout = new TableLayout(context);
    TableLayout.LayoutParams tableLayoutParams = new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT);
    tableLayout.setLayoutParams(tableLayoutParams);
    scrollView.addView(tableLayout);

    // Add header.
    {
        TableRow row = new TableRow(context);
        row.setLayoutParams(new TableRow.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
        tableLayout.addView(row);

        TextView tv = new TextView(context);
        tv.setGravity(Gravity.CENTER);
        tv.setPadding(10, 10, 10, 10);
        tv.setText(resources.getString(R.string.player));
        tv.setTypeface(null, Typeface.BOLD);
        row.addView(tv);

        tv = new TextView(context);
        tv.setGravity(Gravity.CENTER);
        tv.setPadding(10, 10, 10, 10);
        tv.setText(resources.getString(R.string.trains));
        tv.setTypeface(null, Typeface.BOLD);
        row.addView(tv);

        tv = new TextView(context);
        tv.setGravity(Gravity.CENTER);
        tv.setPadding(10, 10, 10, 10);
        tv.setText(resources.getString(R.string.contracts));
        tv.setTypeface(null, Typeface.BOLD);
        row.addView(tv);

        tv = new TextView(context);
        tv.setGravity(Gravity.CENTER);
        tv.setPadding(10, 10, 10, 10);
        tv.setText(resources.getString(R.string.bonuses));
        tv.setTypeface(null, Typeface.BOLD);
        row.addView(tv);

    }

    // Add rows.
    for (int i = 0; i < players.getNum(); i++) {
        TableRow row = new TableRow(context);
        row.setLayoutParams(new TableRow.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
        tableLayout.addView(row);

        ToggleButton toggleButton = new ToggleButton(context);
        toggleButton.setGravity(Gravity.CENTER);
        toggleButton.setPadding(10, 10, 10, 10);
        toggleButton.setText(playerNames[i]);
        toggleButton.setClickable(false);
        Drawable drawable = drawablesArray.getDrawable(i);
        int sdk = android.os.Build.VERSION.SDK_INT;
        if (sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) {
            toggleButton.setBackgroundDrawable(drawable);
        } else {
            toggleButton.setBackground(drawable);
        }
        toggleButton.setTextColor(resources.getColor(playerTextColorsIds[i]));
        row.addView(toggleButton);

        TextView tv = new TextView(context);
        tv.setGravity(Gravity.CENTER);
        tv.setPadding(10, 10, 10, 10);
        row.addView(tv);

        tv = new TextView(context);
        tv.setGravity(Gravity.CENTER);
        tv.setPadding(10, 10, 10, 10);
        row.addView(tv);

        tv = new TextView(context);
        tv.setGravity(Gravity.CENTER);
        tv.setPadding(10, 10, 10, 10);
        row.addView(tv);

    }

    Bundle args = getArguments();
    if (args == null) {
        Log.e(TAG, "onCreateView: missing arguments");
        return rootView;
    }

    drawablesArray.recycle();
    playerTextColorsArray.recycle();

    // final int index = args.getInt(ARG_INDEX);
    // final String tabSpec = args.getString(ARG_TAB_SPEC);

    return rootView;
}

From source file:com.android.calculator3.Calculator2.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);//from w  w  w.java2 s.  co m

    //??????????sin?cos
    //ViewPager?????
    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());

    //???
    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 (!ViewConfiguration.get(this).hasPermanentMenuKey()) {
        //??
        createFakeMenu();
    }

    //??
    mLogic.resumeWithHistory();
    //
    updateDeleteMode();
}