Example usage for android.widget TabHost setCurrentTab

List of usage examples for android.widget TabHost setCurrentTab

Introduction

In this page you can find the example usage for android.widget TabHost setCurrentTab.

Prototype

public void setCurrentTab(int index) 

Source Link

Usage

From source file:org.runnerup.view.MainLayout.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    setContentView(R.layout.main);//  w ww .ja v  a 2 s  . co m

    int versionCode = 0;
    UpgradeState upgradeState = UpgradeState.UNKNOWN;
    SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
    Editor editor = pref.edit();
    try {
        PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
        versionCode = pInfo.versionCode;
        int version = pref.getInt("app-version", -1);
        if (version == -1) {
            upgradeState = UpgradeState.NEW;
        } else if (versionCode == version) {
            upgradeState = UpgradeState.SAME;
        } else if (versionCode > version) {
            upgradeState = UpgradeState.UPGRADE;
        } else if (versionCode < version) {
            upgradeState = UpgradeState.DOWNGRADE;
        }
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }
    editor.putInt("app-version", versionCode);
    boolean km = Formatter.getUseKilometers(getResources(), pref, editor);

    if (upgradeState == UpgradeState.NEW) {
        editor.putString(getResources().getString(R.string.pref_autolap),
                Double.toString(km ? Formatter.km_meters : Formatter.mi_meters));
    }
    editor.commit();

    // clear basicTargetType between application startup/shutdown
    pref.edit().remove(getString(R.string.pref_basic_target_type)).commit();

    Log.e(getClass().getName(),
            "app-version: " + versionCode + ", upgradeState: " + upgradeState + ", km: " + km);

    // convert pref_mute to pref_mute_bool
    Resources res = getResources();
    try {
        if (pref.contains(res.getString(R.string.pref_mute))) {
            String v = pref.getString(res.getString(R.string.pref_mute), "no");
            editor.putBoolean(res.getString(R.string.pref_mute_bool), v.equalsIgnoreCase("yes"));
            editor.remove(res.getString(R.string.pref_mute));
            editor.commit();
        }
    } catch (Exception e) {
    }

    PreferenceManager.setDefaultValues(this, R.xml.settings, false);
    PreferenceManager.setDefaultValues(this, R.xml.audio_cue_settings, true);

    TabHost tabHost = getTabHost(); // The activity TabHost

    tabHost.addTab(tabHost.newTabSpec("Start")
            .setIndicator(getString(R.string.Start), myGetDrawable(R.drawable.ic_tab_main))
            .setContent(new Intent(this, StartActivity.class)));

    tabHost.addTab(tabHost.newTabSpec("Feed")
            .setIndicator(getString(R.string.feed), myGetDrawable(R.drawable.ic_tab_feed))
            .setContent(new Intent(this, FeedActivity.class)));

    tabHost.addTab(tabHost.newTabSpec("History")
            .setIndicator(getString(R.string.History), myGetDrawable(R.drawable.ic_tab_history))
            .setContent(new Intent(this, HistoryActivity.class)));

    tabHost.addTab(tabHost.newTabSpec("Settings")
            .setIndicator(getString(R.string.Settings), myGetDrawable(R.drawable.ic_tab_setup))
            .setContent(new Intent(this, SettingsActivity.class)));

    tabHost.setCurrentTab(0);
    WidgetUtil.addLegacyOverflowButton(getWindow());

    if (upgradeState == UpgradeState.UPGRADE) {
        whatsNew();
    }
    //GPS is essential, always nag user if not granted
    requestGpsPermissions(this, tabHost.getCurrentView());

    //Import workouts/schemes. No permission needed
    handleBundled(getApplicationContext().getAssets(), "bundled", getFilesDir().getPath() + "/..");

    // if we were called from an intent-filter because user opened "runnerup.db.export", load it
    final Uri data = getIntent().getData();
    if (data != null) {
        if (SettingsActivity.requestReadStoragePermissions(MainLayout.this)) {
            String filePath = null;
            if ("content".equals(data.getScheme())) {
                Cursor cursor = this.getContentResolver().query(data,
                        new String[] { android.provider.MediaStore.Images.ImageColumns.DATA }, null, null,
                        null);
                cursor.moveToFirst();
                filePath = cursor.getString(0);
                cursor.close();
            } else {
                filePath = data.getPath();
            }
            Log.i(getClass().getSimpleName(), "Importing database from " + filePath);
            DBHelper.importDatabase(MainLayout.this, filePath);
        } else {
            Toast.makeText(this, "Storage permission not granted in Android settings, db is not imported.",
                    Toast.LENGTH_SHORT).show();
        }
    }
}

From source file:com.example.mydemos.view.RingtonePickerActivity.java

/** Called when the activity is first created. */
@Override//from   ww w .j a va2s . c  om
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.ringtone_picker);
    CharSequence sysTitle = (CharSequence) getResources().getText(R.string.sys_tone);
    CharSequence MusicTitle = (CharSequence) getResources().getText(R.string.sd_music);
    CharSequence RecordTitle = (CharSequence) getResources().getText(R.string.record_tone);
    Intent intent = getIntent();
    toneType = intent.getIntExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, -1);

    Log.e("duwenhua", "ringPick get toneType:" + toneType);

    //! by duwenhua
    //if(toneType == RingtoneManager.TYPE_RINGTONE_SECOND)
    //    toneType = RINGTONE_TYPE;

    //! by duwenhua
    mHasDefaultItem = intent.getBooleanExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
    mUriForDefaultItem = intent.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI);
    //Log.i("lys", "mUriForDefaultItem == " + mUriForDefaultItem);
    if (savedInstanceState != null) {
        mSelectedId = savedInstanceState.getLong(SAVE_CLICKED_POS, -1);
    }
    //Log.i("lys", "mUriForDefaultItem 1== " + mUriForDefaultItem+", mSelectedId =="+mSelectedId);      
    mHasSilentItem = intent.getBooleanExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true);
    mExistingUri = intent.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI);
    //if(mUriForDefaultItem != null)
    //{
    //    mSelectedId = ContentUris.parseId(mUriForDefaultItem);
    //}

    //Log.i("lys", "RingtonePickerActivity.java onCreate mExistingUri == " + mExistingUri);   
    //String action = getIntent().getAction();
    //Log.i("lys", "PT Intent action == " + action);

    if (toneType == NOTIFICATION_TYPE) {
        mUriForDefaultItem = Settings.System.DEFAULT_NOTIFICATION_URI;
    } else if (toneType == RINGTONE_TYPE) {
        mUriForDefaultItem = Settings.System.DEFAULT_RINGTONE_URI;
    } else if (toneType == ALARM_TYPE) {
        mUriForDefaultItem = Settings.System.DEFAULT_ALARM_ALERT_URI;
    }

    if (isAvailableToCheckRingtone() == true) {
        Ringtone ringtone_DefaultItem = checkRingtone_reflect(this, mUriForDefaultItem, toneType);
        if (ringtone_DefaultItem != null && ringtone_DefaultItem.getUri() != null) {
            mUriForDefaultItem = ringtone_DefaultItem.getUri();
            Log.i("lys", "RingtoneManager.getRingtone  mUriForDefaultItem== " + mUriForDefaultItem);
        } else {
            //mUriForDefaultItem = 'content/medial/';
            /*ZTE_AUDIO_LIYANG 2014/06/30 fix bug for ringtone when remove sdcard start */
            String originalRingtone = Settings.System.getString(getApplicationContext().getContentResolver(),
                    "ringtone_original");
            if (originalRingtone != null && !TextUtils.isEmpty(originalRingtone)) {
                mUriForDefaultItem = Uri.parse(originalRingtone);
                Log.e("liyang", "select riongtone error  ,change to originalRingtone == " + mExistingUri);
            }
            /*ZTE_AUDIO_LIYANG 2014/06/30 fix bug for ringtone when remove sdcard end */
            Log.i("lys", "mUriForDefaultItem set as default mUriForDefaultItem== 222");
        }

        if (mExistingUri != null) {
            Ringtone ringtone = checkRingtone_reflect(this, mExistingUri, toneType);
            if (ringtone != null && ringtone.getUri() != null) {
                //mUriForDefaultItem = ringtone.getUri(); 
                mExistingUri = ringtone.getUri();
                Log.i("lys", "RingtoneManager.getRingtone  mExistingUri== " + mExistingUri);
            } else {
                mExistingUri = mUriForDefaultItem;
                Log.i("lys", "mExistingUri set as default mExistingUri== " + mExistingUri);
            }
        }
    }

    boolean includeDrm = intent.getBooleanExtra(RingtoneManager.EXTRA_RINGTONE_INCLUDE_DRM, false);
    Log.e("lys", "includeDrm ==" + includeDrm);
    mRingtoneManager = new RingtoneManager(this);
    mRingtoneManager.setIncludeDrm(includeDrm);
    if (toneType != -1) {
        mRingtoneManager.setType(toneType);
    }

    setVolumeControlStream(mRingtoneManager.inferStreamType());
    //   toneActivityType = mRingtoneManager.getActivityType();
    if (toneType == ALARM_TYPE) {
        sysTitle = (CharSequence) getResources().getText(R.string.alarm_tone);
    } else if (toneType == NOTIFICATION_TYPE) {
        sysTitle = (CharSequence) getResources().getText(R.string.notification_tone);
    }

    listView = new ListView(this);
    listView.setOnItemClickListener(this);
    //listView.setBackgroundColor(#ff5a5a5a);
    listView.setFastScrollEnabled(true);
    //listView.setFastScrollAlwaysVisible(true);
    listView.setEmptyView(findViewById(android.R.id.empty));
    //mHasSilentItem = intent.getBooleanExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true);

    //mHasDefaultItem = true; //temp
    if (mHasDefaultItem) {
        //chengcheng
        addDefaultStaticItem(listView, com.android.internal.R.string.ringtone_default);

    }

    setDefaultRingtone();

    if (mHasSilentItem) {
        // chengcheng
        addSilendStaticItem(listView, com.android.internal.R.string.ringtone_silent);
    }
    audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    mAudioFocusListener = new OnAudioFocusChangeListener() {
        public void onAudioFocusChange(int focusChange) {

        }
    };

    okBtn = (Button) findViewById(R.id.ok);
    okBtn.setOnClickListener(this);
    cancelBtn = (Button) findViewById(R.id.cancel);
    cancelBtn.setOnClickListener(this);

    TabHost mTabHost = (TabHost) findViewById(android.R.id.tabhost);
    mTabHost.setup();
    mTabHost.addTab(mTabHost.newTabSpec("tab_system").setIndicator(sysTitle, null).setContent(this));
    mTabHost.addTab(mTabHost.newTabSpec("tab_music").setIndicator(MusicTitle, null).setContent(this));
    mTabHost.addTab(mTabHost.newTabSpec("tab_record").setIndicator(RecordTitle, null).setContent(this));
    mTabHost.setCurrentTab(0);
    mTabHost.setOnTabChangedListener(new OnTabChangeListener() {
        @Override
        public void onTabChanged(String tabId) {
            // stopMediaPlayer();
            createTabContent(tabId);
        }
    });
}

From source file:edu.nd.darts.cimon.NDroidAdmin.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.administrator);
    // Toast.makeText(getBaseContext(), "This is",
    // Toast.LENGTH_LONG).show();

    startService(new Intent(this, NDroidService.class));

    Resources res = getResources(); // Resource object to get Drawables
    TabHost tabHost = getTabHost(); // The activity TabHost
    TabHost.TabSpec spec; // Reusable TabSpec for each tab
    Intent intent; // Reusable Intent for each tab

    // Create an Intent to launch an Activity for the tab (to be reused)
    // intent = new Intent().setClass(this, NDroidSystem.class);
    intent = new Intent().setClass(this, CimonListView.class);
    intent.putExtra("key", Metrics.TYPE_SYSTEM);

    // Initialize a TabSpec for each tab and add it to the TabHost
    spec = tabHost.newTabSpec("system").setIndicator("System", res.getDrawable(R.drawable.icon_system))
            .setContent(intent);/*from ww  w.  j  a va  2  s. c om*/
    tabHost.addTab(spec);

    // Do the same for the other tabs
    // intent = new Intent().setClass(this, NDroidSensor.class);
    intent = new Intent().setClass(this, CimonListView.class);
    intent.putExtra("key", Metrics.TYPE_SENSOR);
    spec = tabHost.newTabSpec("sensors").setIndicator("Sensors", res.getDrawable(R.drawable.icon_sensor))
            .setContent(intent);
    tabHost.addTab(spec);

    // intent = new Intent().setClass(this, NDroidUser.class);
    intent = new Intent().setClass(this, CimonListView.class);
    intent.putExtra("key", Metrics.TYPE_USER);
    spec = tabHost.newTabSpec("user").setIndicator("User Activity", res.getDrawable(R.drawable.icon_user))
            .setContent(intent);
    tabHost.addTab(spec);

    tabHost.setCurrentTab(0);

    SharedPreferences appPrefs = getSharedPreferences(SHARED_PREFS, Context.MODE_PRIVATE);

    int storedVersion = appPrefs.getInt(PREF_VERSION, -1);

    int appVersion = -1;

    try {
        appVersion = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode;
    } catch (NameNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    if (DebugLog.DEBUG)
        Log.d(TAG, "NDroidAdmin.onCreate - appVersion:" + appVersion + " storedVersion:" + storedVersion);

    if (appVersion > storedVersion) {

        new Thread(new Runnable() {
            public void run() {
                List<MetricService<?>> serviceList;
                serviceList = MetricService.getServices(Metrics.TYPE_SYSTEM);
                for (MetricService<?> mService : serviceList) {
                    mService.insertDatabaseEntries();
                }
                serviceList.clear();
                serviceList = MetricService.getServices(Metrics.TYPE_SENSOR);
                for (MetricService<?> mService : serviceList) {
                    mService.insertDatabaseEntries();
                }
                serviceList.clear();
                serviceList = MetricService.getServices(Metrics.TYPE_USER);
                for (MetricService<?> mService : serviceList) {
                    mService.insertDatabaseEntries();
                }
                serviceList.clear();
            }
        }).start();

        SharedPreferences.Editor editor = appPrefs.edit();
        editor.putInt(PREF_VERSION, appVersion);
        editor.commit();
    }
}

From source file:com.momock.outlet.tab.PagerTabOutlet.java

public void attach(TabHolder target) {
    Logger.check(target != null, "Parameter target cannot be null!");
    Logger.check(target.getTabContent() instanceof ViewPager,
            "The PagerTabOutlet must contains a ViewPager content!");
    this.target = target;
    final TabHost tabHost = target.getTabHost();
    final ViewPager tabContent = (ViewPager) target.getTabContent();
    plugs = getPlugs();/*from   ww w. j  a  v a  2 s. c  om*/

    ViewPager pager = (ViewPager) target.getTabContent();
    for (int i = 0; i < plugs.getItemCount(); i++) {
        ITabPlug plug = (ITabPlug) plugs.getItem(i);
        Logger.check(plug.getContent() instanceof ViewHolder,
                "The plug of PagerTabOutlet must include a ViewHolder!");
        ((ViewHolder) plug.getContent()).reset();
    }
    pager.setAdapter(new PagerAdapter() {

        @Override
        public int getCount() {
            return plugs.getItemCount();
        }

        @Override
        public boolean isViewFromObject(View view, Object object) {
            return view == object;
        }

        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            ITabPlug plug = (ITabPlug) plugs.getItem(position);
            View view = ((ViewHolder) plug.getContent()).getView();
            container.addView(view);
            return view;
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            container.removeView((View) object);
        }
    });

    tabContent.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageSelected(int position) {
            TabWidget widget = tabHost.getTabWidget();
            int oldFocusability = widget.getDescendantFocusability();
            widget.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
            tabHost.setCurrentTab(position);
            widget.setDescendantFocusability(oldFocusability);
        }

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

        }

        @Override
        public void onPageScrollStateChanged(int state) {

        }
    });
    tabHost.setup();
    tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {

        @Override
        public void onTabChanged(String tabId) {
            int index = tabHost.getCurrentTab();
            ITabPlug plug = (ITabPlug) plugs.getItem(index);
            setActivePlug(plug);
            tabContent.setCurrentItem(index, true);
        }
    });
    for (int i = 0; i < plugs.getItemCount(); i++) {
        final ITabPlug plug = (ITabPlug) plugs.getItem(i);
        Logger.check(plug.getContent() instanceof ViewHolder,
                "Plug in PagerTabOutlet must contains a ViewHolder content!");

        TabHost.TabSpec spec = tabHost.newTabSpec("" + i);
        target.setTabIndicator(spec, plug);
        spec.setContent(new TabContentFactory() {

            @Override
            public View createTabContent(String tag) {
                View v = new View(tabHost.getContext());
                v.setMinimumWidth(0);
                v.setMinimumHeight(0);
                return v;
            }

        });
        tabHost.addTab(spec);
        if (getActivePlug() == plug)
            tabHost.setCurrentTab(i);
    }
}

From source file:com.github.colorchief.colorchief.MainActivity.java

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

    setContentView(R.layout.activity_main);

    final TabHost tabHost = (TabHost) findViewById(R.id.tabHost);
    tabHost.setup();//  ww  w.ja va2 s.  c o m

    final TabHost.TabSpec tabImageView = tabHost.newTabSpec("Image View");
    final TabHost.TabSpec tabSettings = tabHost.newTabSpec("Settings");
    final TabHost.TabSpec tabAbout = tabHost.newTabSpec("About");

    tabImageView.setIndicator("", ContextCompat.getDrawable(this, R.drawable.ic_action_picture));
    tabImageView.setContent(R.id.tabImageView);

    tabSettings.setIndicator("", ContextCompat.getDrawable(this, R.drawable.ic_action_gear));
    tabSettings.setContent(R.id.tabSettings);

    tabAbout.setIndicator("", ContextCompat.getDrawable(this, R.drawable.ic_action_help));
    tabAbout.setContent(R.id.tabAbout);

    /** Add the tabs  to the TabHost to display. */
    tabHost.addTab(tabImageView);
    tabHost.addTab(tabSettings);
    tabHost.addTab(tabAbout);

    colorLUT.initLUT(LUT_SIZE, LUT_SIZE, LUT_SIZE);

    //check savedInstance
    // for Tab state and set active tab accordingly
    // for LUT values and update (restore) accordingly
    if (savedInstanceState != null) {
        tabHost.setCurrentTab(savedInstanceState.getInt("Active Tab"));
        colorLUT.setColorLutArray(savedInstanceState.getIntArray("Color LUT"));
    }

    ((SeekBar) findViewById(R.id.seekBarChromaPowerFactor)).setMax(POWER_FACTOR_SEEK_BAR_MAX);
    ((SeekBar) findViewById(R.id.seekBarChromaPowerFactor)).setProgress(getSeekPosition(powerFactor));

    if (Lselect == LutCalculate.L_SELECT_IN) {
        ((RadioButton) findViewById(R.id.radioButtonLin)).setChecked(true);
        ((RadioButton) findViewById(R.id.radioButtonLout)).setChecked(false);
    } else if (Lselect == LutCalculate.L_SELECT_OUT) {
        ((RadioButton) findViewById(R.id.radioButtonLin)).setChecked(false);
        ((RadioButton) findViewById(R.id.radioButtonLout)).setChecked(true);
    }
    if (Cselect == LutCalculate.C_SELECT_ABSOLUTE) {
        ((RadioButton) findViewById(R.id.radioButtonCin)).setChecked(true);
        ((RadioButton) findViewById(R.id.radioButtonCrelative)).setChecked(false);
        ((SeekBar) findViewById(R.id.seekBarChromaPowerFactor)).setEnabled(false);

    } else if (Cselect == LutCalculate.C_SELECT_RELATIVE) {
        ((RadioButton) findViewById(R.id.radioButtonCin)).setChecked(false);
        ((RadioButton) findViewById(R.id.radioButtonCrelative)).setChecked(true);
        ((SeekBar) findViewById(R.id.seekBarChromaPowerFactor)).setEnabled(true);
    }

    if (uriIccProfileIn != null)
        iccProfileIn.loadFromFile(uriIccProfileIn);
    if (uriIccProfileOut != null)
        iccProfileOut.loadFromFile(uriIccProfileOut);

    if (bitmapLoaded) {

        transformImage();
        updateImageViewer();

    } else {
        ((ImageView) findViewById(R.id.imageView)).setImageBitmap(
                BitmapFactory.decodeResource(getResources(), R.drawable.ic_action_folder_open_blue));

    }

    ((ImageView) findViewById(R.id.imageView)).addOnLayoutChangeListener(new View.OnLayoutChangeListener() {

        @Override
        public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop,
                int oldRight, int oldBottom) {
            // if layout is not complete we will get all zero values for the positions, so ignore the event
            if (left == 0 && top == 0 && right == 0 && bottom == 0) {
                return;
            } else {
                if (bitmapLoaded) {
                    try {
                        decodeImageUri(uriBitmapOriginal, (ImageView) findViewById(R.id.imageView));
                    } catch (FileNotFoundException e) {
                        Log.e(TAG, "Failed to grab Bitmap: " + e);
                    }
                    //if (iccProfileOut.isValidProfile() && iccProfileIn.isValidProfile())
                    transformImage();
                    updateImageViewer();

                }
            }

        }
    });

    ((SeekBar) findViewById(R.id.seekBarChromaPowerFactor))
            .setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
                @Override
                public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {

                }

                @Override
                public void onStartTrackingTouch(SeekBar seekBar) {

                }

                @Override
                public void onStopTrackingTouch(SeekBar seekBar) {
                    powerFactor = getPowerFactor(seekBar.getProgress());
                    //convertImage(seekBar);
                    //updateImageViewer();
                }
            });

    //when switching tabs, make sure:
    //a: update the image when switching to the imageview tab in case any settings changes were made
    //b: hide the color controls overlay if we are not on the imageview tab
    tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {
        @Override
        public void onTabChanged(String tabId) {
            if (tabId.equals(tabImageView.getTag())) {
                //Log.d(TAG,"Tab changed to image view");

                if (iccProfileIn.isValidProfile() && iccProfileOut.isValidProfile() && bitmapLoaded) {
                    recalculateTransform();
                    transformImage();
                    updateImageViewer();
                }
            } else if (tabId.equals(tabAbout.getTag())) {
                ((LinearLayout) findViewById(R.id.overlayColorControl)).setVisibility(View.INVISIBLE);
                InputStream inputStream = getResources().openRawResource(R.raw.about);
                ByteArrayOutputStream byteArrayStream = new ByteArrayOutputStream();
                try {
                    int bytesRead = inputStream.read();
                    while (bytesRead != -1) {
                        byteArrayStream.write(bytesRead);
                        bytesRead = inputStream.read();
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }

                //TextView textViewAbout = (TextView) findViewById(R.id.textViewAbout);
                //textViewAbout.setText(Html.fromHtml(byteArrayStream.toString()));
                WebView webViewAbout = (WebView) findViewById(R.id.webViewAbout);
                webViewAbout.loadDataWithBaseURL(null, byteArrayStream.toString(), "text/html", "utf-8", null);
            } else {
                ((LinearLayout) findViewById(R.id.overlayColorControl)).setVisibility(View.INVISIBLE);
            }
        }
    });

}

From source file:com.momock.outlet.tab.FragmentTabOutlet.java

public void attach(FragmentTabHolder tabHolder) {
    Logger.check(tabHolder != null, "Parameter tabHolder cannot be null!");
    this.target = tabHolder;
    TabHost tabHost = target.getTabHost();
    final IDataList<IPlug> plugs = getPlugs();
    tabHost.setup();/*  w  w  w . j  av a 2s .c  om*/
    tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {

        @Override
        public void onTabChanged(String tabId) {
            new Handler().post(new Runnable() {

                @Override
                public void run() {
                    int index = target.getTabHost().getCurrentTab();
                    int id = target.getTabContentId();
                    ITabPlug plug = (ITabPlug) plugs.getItem(index);
                    setActivePlug(plug);

                    FragmentManager fm = target.getFragmentManager();
                    if (fm != null && plug.getContent() instanceof FragmentHolder) {
                        try {
                            FragmentTransaction ft = fm.beginTransaction();
                            FragmentHolder fh = (FragmentHolder) plug.getContent();
                            ft.replace(id, fh.getFragment());
                            ft.commit();
                            fm.executePendingTransactions();
                        } catch (Exception e) {
                            Logger.error(e);
                        }
                    }
                }

            });
        }
    });
    for (int i = 0; i < plugs.getItemCount(); i++) {
        final ITabPlug plug = (ITabPlug) plugs.getItem(i);
        if (plug.getContent() instanceof FragmentHolder) {
            TabHost.TabSpec spec = tabHost.newTabSpec("" + i);
            target.setTabIndicator(spec, plug);
            spec.setContent(new TabContentFactory() {

                @Override
                public View createTabContent(String tag) {
                    View v = new View(target.getTabHost().getContext());
                    v.setMinimumWidth(0);
                    v.setMinimumHeight(0);
                    return v;
                }

            });
            tabHost.addTab(spec);
            if (getActivePlug() == plug)
                tabHost.setCurrentTab(i);
        }
    }
}

From source file:com.tutor.fragment.ViewPageFragment.java

private boolean initialjfTabHostFromWeb(LayoutInflater inflater, View mView) {
    List<FDItemTyeModel> jfItems = GetjfItems();
    if (jfItems == null || jfItems.size() == 0) {
        return false;
    }/* w  w  w  . ja va  2s .c  o  m*/
    final TabHost tabHost = (TabHost) mView.findViewById(R.id.jf_tabhost);
    tabHost.setup();
    View tabItem = inflater.inflate(R.layout.tab_fd_widebg, null);
    TextView tbTabItemTitle = (TextView) tabItem.findViewById(R.id.tvTabItemTitle);
    for (int i = 0; i < 3; i++) {

        if (i == 2) {
            tabItem = inflater.inflate(R.layout.tab_fd_widebg, null);
            tbTabItemTitle = (TextView) tabItem.findViewById(R.id.tvTabItemTitle);
            tbTabItemTitle.setText("");
            tabHost.addTab(tabHost.newTabSpec("-1").setIndicator(tabItem).setContent(R.id.tab3));
            setJFListViewAdapter(tabHost);
            break;
        }
        switch (i) {
        case 0:
            InitialJfItemInf(jfItems.get(i).getItem_ID());
            tbTabItemTitle.setText(jfItems.get(i).getItem_Name());
            tabHost.addTab(tabHost.newTabSpec(jfItems.get(i).getItem_Name()).setIndicator(tabItem)
                    .setContent(R.id.tab1));
            break;
        case 1:
            tabItem = inflater.inflate(R.layout.tab_fd_widebg, null);
            tbTabItemTitle = (TextView) tabItem.findViewById(R.id.tvTabItemTitle);
            tbTabItemTitle.setText(jfItems.get(i).getItem_Name());
            tabHost.addTab(tabHost.newTabSpec(jfItems.get(i).getItem_Name()).setIndicator(tabItem)
                    .setContent(R.id.tab2));
            break;
        }
    }

    tabHost.setOnTabChangedListener(new OnTabChangeListener() {
        @Override
        public void onTabChanged(String tabId) {
            if (tabId != "-1") {
                int itemId = Integer.parseInt(jfTypesMap.get(tabId.toString()).toString());
                InitialJfItemInf(itemId);
                setJFListViewAdapter(tabHost);
            } else {
                tabHost.setCurrentTab(0);
                Intent intent = new Intent(getActivity(), MoreActivity.class);

                intent.putExtra("Flag", "jf");
                startActivity(intent);
            }
        }
    });

    return true;
}

From source file:azad.hallaji.farzad.com.masirezendegi.ExplainMoshaver.java

void postgetData() {

    ProgressBar progressbarsandaha = (ProgressBar) findViewById(R.id.progressbarsandaha);
    progressbarsandaha.setVisibility(View.VISIBLE);

    MyRequestQueue = Volley.newRequestQueue(this);

    String url = "http://telyar.dmedia.ir/webservice/Get_adviser_profile/";
    StringRequest MyStringRequest = new StringRequest(Request.Method.POST, url,
            new Response.Listener<String>() {

                @Override//from   w w w . j  av  a  2 s. co m
                public void onResponse(String response) {
                    //This code is executed if the server responds, whether or not the response contains data.
                    //The String 'response' contains the server's response.
                    Log.i("ExplainMoshaver", response);
                    //Toast.makeText(getApplicationContext(), response , Toast.LENGTH_LONG).show();
                    updatelistview(response);

                }
            }, new Response.ErrorListener() { //Create an error listener to handle errors appropriately.
                @Override
                public void onErrorResponse(VolleyError error) {
                    //This code is executed if there is an error.
                }
            }) {
        protected Map<String, String> getParams() {
            Map<String, String> MyData = new HashMap<String, String>();
            //Log.i("asasasasasasa",adviseridm+"/"+GlobalVar.getDeviceID());
            MyData.put("adviserid", adviseridm); //Add the data you'd like to send to the server.
            MyData.put("deviceid", GlobalVar.getDeviceID()); //Add the data you'd like to send to the server.
            MyData.put("userid", GlobalVar.getUserID()); //Add the data you'd like to send to the server.
            Log.i("ExplainMoshaver", MyData.toString());

            return MyData;
        }

        @Override
        protected void onFinish() {

            ProgressBar progressbarsandaha = (ProgressBar) findViewById(R.id.progressbarsandaha);
            progressbarsandaha.setVisibility(View.INVISIBLE);

            TabHost tabHost = (TabHost) findViewById(android.R.id.tabhost);

            TabHost.TabSpec tabSpec3 = tabHost.newTabSpec("nazar");
            TabHost.TabSpec tabSpec2 = tabHost.newTabSpec("madarek");
            TabHost.TabSpec tabSpec1 = tabHost.newTabSpec("map");

            tabSpec3.setIndicator("");
            Intent intent1 = new Intent(ExplainMoshaver.this, ListeComments.class);
            intent1.putExtra("adviseridm", adviseridm);
            intent1.putExtra("comments", comments);
            /*intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            intent1.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
            intent1.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);*/
            Log.i("aaaaaaaaaaaaaaa", comments + " ");
            tabSpec3.setContent(intent1);

            tabSpec2.setIndicator("");
            Intent intent2 = new Intent(ExplainMoshaver.this, ListeLiecence.class);
            intent2.putExtra("adviseridm", adviseridm);
            intent2.putExtra("License", License);
            /*intent2.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            intent2.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
            intent2.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);*/
            tabSpec2.setContent(intent2);

            tabSpec1.setIndicator("");
            final Intent intent = new Intent(ExplainMoshaver.this, MapsActivity.class);
            intent.putExtra("adviseridm", adviseridm);
            intent.putExtra("Mainplace", Mainplace);
            intent.putExtra("menuya", "ya");
            /*intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
            intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);*/
            tabSpec1.setContent(intent);

            tabHost.addTab(tabSpec1);
            tabHost.addTab(tabSpec2);
            tabHost.addTab(tabSpec3);

            tabHost.setCurrentTab(2);
        }
    };

    MyRequestQueue.add(MyStringRequest);
}

From source file:fr.vassela.acrrd.Main.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    try {/*from   w  w w.j  a v a2  s . c  o  m*/
        localizerManager.setPreferencesLocale(getApplicationContext());
        themeManager.setPreferencesTheme(getApplicationContext(), this);

        delegate = AppCompatDelegate.create(this, this);
        delegate.installViewFactory();

        super.onCreate(savedInstanceState);

        delegate.onCreate(savedInstanceState);

        delegate.setContentView(R.layout.main);

        SharedPreferences sharedPreferences = PreferenceManager
                .getDefaultSharedPreferences(getApplicationContext());
        int currentLocaleIndex = Integer.parseInt(sharedPreferences.getString("preferences_locale_set", "0"));
        String currentLocale = localizerManager.getLocale(getApplicationContext()).toString();

        ArrayList<String> slideMenuTitles = new ArrayList<String>();
        slideMenuTitles.add(getApplicationContext().getString(R.string.preferences_locale).toString());
        //slideMenuTitles.add(getApplicationContext().getString(R.string.main_toolbar_test).toString());
        slideMenuTitles.add(getApplicationContext().getString(R.string.main_toolbar_preferences).toString());
        slideMenuTitles.add(getApplicationContext().getString(R.string.main_toolbar_log).toString());
        slideMenuTitles.add(getApplicationContext().getString(R.string.main_toolbar_about).toString());
        slideMenuTitles.add(getApplicationContext().getString(R.string.main_toolbar_exit).toString());

        ArrayList<String> slideMenuSubtitles = new ArrayList<String>();
        slideMenuSubtitles.add(currentLocale);
        //slideMenuSubtitles.add(getApplicationContext().getString(R.string.main_toolbar_test_description).toString());
        slideMenuSubtitles.add(
                getApplicationContext().getString(R.string.main_toolbar_preferences_description).toString());
        slideMenuSubtitles
                .add(getApplicationContext().getString(R.string.main_toolbar_log_description).toString());
        slideMenuSubtitles
                .add(getApplicationContext().getString(R.string.main_toolbar_about_description).toString());
        slideMenuSubtitles
                .add(getApplicationContext().getString(R.string.main_toolbar_exit_description).toString());

        ArrayList<Integer> slideMenuIcons = new ArrayList<Integer>();
        slideMenuIcons.add(themeManager.getLocaleFlag(getApplicationContext(), currentLocaleIndex));
        slideMenuIcons.add(R.drawable.ic_menu_preferences);
        //slideMenuIcons.add(R.drawable.ic_menu_preferences);
        slideMenuIcons.add(R.drawable.ic_menu_archive);
        slideMenuIcons.add(R.drawable.ic_menu_info_details);
        slideMenuIcons.add(R.drawable.ic_menu_revert);

        drawerList = (ListView) findViewById(R.id.drawer_list);
        drawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);

        SlidingMenuAdapter slidingMenuAdapter = new SlidingMenuAdapter(this, slideMenuTitles,
                slideMenuSubtitles, slideMenuIcons);

        drawerList.setAdapter(slidingMenuAdapter);

        drawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                switch (position) {
                case 0:
                    break;

                /*case 0 :
                   drawerLayout.closeDrawers();
                   startActivity(new Intent(getApplicationContext(), Test.class));
                   break;*/

                case 1:
                    drawerLayout.closeDrawers();
                    startActivity(new Intent(getApplicationContext(), Preferences.class));
                    break;

                case 2:
                    drawerLayout.closeDrawers();
                    startActivity(new Intent(getApplicationContext(), TelephoneCallLogger.class));
                    break;

                case 3:
                    drawerLayout.closeDrawers();
                    startActivity(new Intent(getApplicationContext(), About.class));
                    break;

                case 4:
                    drawerLayout.closeDrawers();
                    RecordServiceManager recordServiceManager = new RecordServiceManager();
                    boolean isRecordServiceRunning = recordServiceManager.isRunning(getApplicationContext());

                    if (isRecordServiceRunning == false) {
                        MonitoringServiceManager monitoringServiceManager = new MonitoringServiceManager();
                        monitoringServiceManager.stopService(getApplicationContext());

                        PurgeServiceManager purgeServiceManager = new PurgeServiceManager();
                        purgeServiceManager.stopService(getApplicationContext());
                    }

                    moveTaskToBack(true);
                    onBackPressed();
                    break;

                }

            }
        });

        toolbar = (Toolbar) findViewById(R.id.main_toolbar);
        delegate.setSupportActionBar(toolbar);
        delegate.setTitle(getString(R.string.main_toolbar));
        delegate.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        delegate.getSupportActionBar().setDisplayShowHomeEnabled(true);
        delegate.getSupportActionBar().setHomeButtonEnabled(true);

        TabHost tabhost = (TabHost) findViewById(android.R.id.tabhost);
        TabWidget tabwidget = tabhost.getTabWidget();

        TabSpec tab_home = tabhost.newTabSpec(getString(R.string.main_tab_home));
        TabSpec tab_records = tabhost.newTabSpec(getString(R.string.main_tab_records));
        TabSpec tab_preferences = tabhost.newTabSpec(getString(R.string.main_tab_preferences));
        TabSpec tab_about = tabhost.newTabSpec(getString(R.string.main_tab_about));
        TabSpec tab_test = tabhost.newTabSpec("test");

        tab_home.setIndicator(getString(R.string.main_tab_home),
                this.getResources().getDrawable(R.drawable.ic_menu_home));
        tab_home.setContent(new Intent(this, Home.class));

        tab_records.setIndicator(getString(R.string.main_tab_records),
                this.getResources().getDrawable(R.drawable.ic_voice_search));
        tab_records.setContent(new Intent(this, Records.class));

        tab_preferences.setIndicator(getString(R.string.main_tab_preferences),
                this.getResources().getDrawable(R.drawable.ic_menu_preferences));
        tab_preferences.setContent(new Intent(this, Preferences.class));

        tab_about.setIndicator(getString(R.string.main_tab_about),
                this.getResources().getDrawable(R.drawable.ic_menu_info_details));
        tab_about.setContent(new Intent(this, About.class));

        tab_test.setIndicator("test", this.getResources().getDrawable(R.drawable.ic_menu_preferences));
        tab_test.setContent(new Intent(this, Test.class));

        tabhost.addTab(tab_home);
        tabhost.addTab(tab_records);

        Intent intent = getIntent();

        /*String setCurrentTab;
                
        if (savedInstanceState == null)
        {
           Bundle extras = getIntent().getExtras();
                   
           if(extras == null)
           {
         setCurrentTab = null;
           }
           else
           {
         setCurrentTab = extras.getString("setCurrentTab");
           }
        }
        else
        {
           setCurrentTab = (String) savedInstanceState.getSerializable("setCurrentTab");
        }
                
        getIntent().removeExtra("setCurrentTab"); 
                
        if(setCurrentTab.equals("home"))
        {
           tabhost.setCurrentTab(0);
        }
        else if(setCurrentTab.equals("records"))
        {
           tabhost.setCurrentTab(1);
        }
        else
        {
           tabhost.setCurrentTab(0);
        }*/

        if (SHOW_RECORDS.equals(intent.getAction())) {
            tabhost.setCurrentTab(1);
        } else {
            tabhost.setCurrentTab(0);
        }

        initDrawer();

        themeManager.setTabWidget(getApplicationContext(), tabwidget);

    } catch (Exception e) {
        Log.e("Main",
                "onCreate : " + getApplicationContext().getString(R.string.log_main_error_create) + " : " + e);
        databaseManager.insertLog(getApplicationContext(),
                "" + getApplicationContext().getString(R.string.log_main_error_create), new Date().getTime(), 1,
                false);
    }
}

From source file:org.uguess.android.sysinfo.SiragonInfo.java

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

    Util.hookExceptionHandler(getApplicationContext());

    if (Util.SDK_VER < 11) {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
    }//from   www  . j a  va 2  s  .co m

    setContentView(R.layout.main);

    TabHost th = (TabHost) findViewById(android.R.id.tabhost);
    th.setup();

    ViewPager vp = (ViewPager) findViewById(R.id.pager);

    ITabContainer tabContainer = null;

    if (Util.SDK_VER >= 11) {
        // if ( mtdGetActionBar != null
        // && mtdSetDisplayShowTitleEnabled != null
        // && mtdSetNavigationMode != null
        // && mtdSetListNavigationCallbacks != null
        // && mtdSetSelectedNavigationItem != null )
        // {
        // try
        // {
        // Object actionBar = mtdGetActionBar.invoke( this );
        //
        // mtdSetDisplayShowTitleEnabled.invoke( actionBar, false );
        // mtdSetNavigationMode.invoke( actionBar,
        // ActionBar.NAVIGATION_MODE_LIST );
        //
        // tabContainer = new NavListAdapter( this,
        // actionBar,
        // vp,
        // new String[]{
        // getString( R.string.tab_info ),
        // getString( R.string.tab_apps ),
        // getString( R.string.tab_procs ),
        // getString( R.string.tab_netstat )
        // } );
        // }
        // catch ( Exception e )
        // {
        // Log.e( QSystemInfo.class.getName( ),
        // e.getLocalizedMessage( ),
        // e );
        // }
        // }
    }

    if (tabContainer == null) {
        tabContainer = new TabsAdapter(this, th, vp);
    }

    tabContainer.addTab(th.newTabSpec(SiragonManager.class.getName()).setIndicator(getString(R.string.tab_info),
            getResources().getDrawable(R.drawable.info)), SiragonManager.class, null);

    tabContainer.addTab(th.newTabSpec(ApplicationManager.class.getName())
            .setIndicator(getString(R.string.tab_apps), getResources().getDrawable(R.drawable.applications)),
            ApplicationManager.class, null);

    tabContainer.addTab(th.newTabSpec(ProcessManager.class.getName())
            .setIndicator(getString(R.string.tab_procs), getResources().getDrawable(R.drawable.processes)),
            ProcessManager.class, null);

    tabContainer.addTab(th.newTabSpec(NetStateManager.class.getName())
            .setIndicator(getString(R.string.tab_netstat), getResources().getDrawable(R.drawable.connection)),
            NetStateManager.class, null);

    SharedPreferences sp = getSharedPreferences(SiragonManager.PSTORE_SYSINFOMANAGER, Context.MODE_PRIVATE);

    fixTextView(th);

    Util.updateIcons(this, sp);

    if (sp != null) {
        int tab = sp.getInt(SiragonManager.PREF_KEY_DEFAULT_TAB, 0);

        if (tab == 0) {
            tab = sp.getInt(PREF_KEY_LAST_ACTIVE, 1);
        }

        if (tab > 0 && tab < 5) {
            th.setCurrentTab(tab - 1);
        }
    }
}